0
我在OpenCart(版本1.5.6)網站上更改了一些網址,然後又改變了一次; Google開始提醒我已經有死鏈接,現在我正在嘗試通過在.htaccess
中添加手動301重定向來解決問題:我以前每當使用WordPress時都會這樣做。手動301在OpenCart中重定向
我不是可以手動做每個鏈接,我其實更喜歡這種方法。
但是,每當我在.htaccess
中添加一行時,它往往被忽略。
下面是我的.htaccess
文件的內容:
<Files *.ini>
Order deny,allow
Deny from All
</Files>
SetEnv PHPRC /home/shopurl/
Options +FollowSymlinks
Options -Indexes
<FilesMatch "\.(tpl|ini|log)">
Order deny,allow
Deny from all
</FilesMatch>
# SEO URL Settings
RewriteEngine On
RewriteCond %{HTTP_HOST} ^shopurl.com
RewriteRule (.*) http://www.shopurl.com/$1 [R=301,L]
RewriteBase/
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteRule ^download/(.*) /index.php?route=error/not_found [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
<ifModule mod_headers.c>
Header set Connection keep-alive
</ifModule>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/x-javascript application/javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
<ifModule mod_headers.c>
Header append Vary User-Agent
</ifModule>
<FilesMatch "\.(js|css|jpg|png|jpeg|gif|xml|json|txt|pdf|mov|avi|otf|woff|ico|swf)$">
RequestHeader unset Cookie
Header unset Cookie
Header unset Set-Cookie
ErrorDocument 404 'Not Found'
</FilesMatch>
我怎樣才能做到這一點成功?
隊友,感謝您的幫助。它有效,有點..說有點因爲我有類似於 '重寫規則^主要類別/主新類別[R = 301,L]'(它工作正常) 但我也有類似的東西: '重寫規則^主要類別/子貓/主要新類別/子新貓[R = 301,L]'(不起作用...) – Seb
您應該使用:'重寫規則^主要類別$/main-new-category [R = 301,L]'和'RewriteRule^main-category/sub-cat $/main-new-category/sub-new-cat [R = 301,L]'。請注意RewriteRule的第一個參數後的美元符號。 –
如果您想重寫該類別中的所有產品,我還建議您在最後添加一個帶斜槓和全部匹配的版本。例如:'RewriteRule^main-category /(.*)$/main-new-category/$ 1 [R = 301,L]' –