网站使用opencart cms,启用了SEO网址,因此.htaccess看起来:
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [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]
一切都很完美,但我想将301重定向从非www添加到www,所以我补充说:
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule ^(.*) http://www.example.com/$1 [R=301,L]
它工作,但当我尝试重定向链接与类别或产品时,它添加“index.php?route =”
例:
"www.example.com/cats",如果我尝试"example.com/cats"没有"www",链接将显示www.example.com/index.php?route=cats
1 回答
您需要添加所有重定向 before 任何路由规则(例如,您将路由到
index.php
的规则 . 所以您的htaccess文件需要看起来像这样: