1

网站使用 opencart cms,启用了 SEO url,所以 .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]

一切都很完美,但我想添加从非 www 到 www 的 301 重定向,所以我添加了:

RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule ^(.*) http://www.example.com/$1 [R=301,L]

它可以工作,但是当我尝试使用类别或产品重定向链接时,它会添加“index.php?route =”

例子:

“www.example.com/cats”,如果我尝试不带“www”的“example.com/cats”,链接会看起来是 www.example.com/index.php?路线=猫

4

1 回答 1

6

您需要在任何路由规则之前添加所有重定向(例如,您将事物路由到的规则index.php。所以您的 htaccess 文件需要看起来像这样:

# redirect rules first
RewriteCond %{HTTP_HOST} ^mysite.com$ [NC]
RewriteRule ^(.*) http://www.mysite.com/$1 [R=301,L]

# then routing rules
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]
于 2012-12-11T00:23:16.083 回答