我在OpenCart(版本1.5.6)网站上更改了一些网址,然后我再次更改了这些网址;谷歌开始提醒我有死链接,现在我通过在.htaccess
中添加手动301重定向来解决问题:我曾经在使用WordPress时这样做。
我不仅可以手动完成每个链接,实际上我更喜欢这种方法。
但是,每当我在.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>
如何成功实现这一目标?
答案 0 :(得分:1)
在RewriteBase /
行之后添加所有RewriteRules,如下所示:
...
RewriteBase /
RewriteRule ^your-url$ /your-new-url [L,R=301]
RewriteRule ^your-page$ /your-new-page [L,R=301]
RewriteRule ^your-category$ /your-new-category [L,R=301]
RewriteRule ^your-product$ /your-new-product [L,R=301]
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
...
所以重写:
http://www.yoursite.com/your-url
- to -
http://www.yoursite.com/your-new-url
等...