opencart重写.htaccess

RaS*_*She 1 .htaccess url-rewriting opencart

网站使用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]
Run Code Online (Sandbox Code Playgroud)

一切都很完美,但我想将301重定向从非www添加到www,所以我补充说:

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

它工作,但当我尝试重定向链接与类别或产品时,它添加"index.php?route ="

例:

"www.example.com/cats",如果我尝试没有"www"的"example.com/cats",链接会显示www.example.com/index.php吗?route = cats

Jon*_*Lin 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]
Run Code Online (Sandbox Code Playgroud)