RaShe
RaShe

Reputation: 1880

opencart rewrite .htaccess

Website use the opencart cms, SEO url enabled, so the .htaccess looks :

 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]

all works perfect, but i wanted to add the 301 redirect from non www to www, so i added:

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

It works, but when i try to redirect link with category or product it adds "index.php?route="

Example:

"www.example.com/cats", if i try "example.com/cats" without "www" the link will look www.example.com/index.php?route=cats

Upvotes: 1

Views: 9225

Answers (1)

Jon Lin
Jon Lin

Reputation: 143876

You need to add all of your redirects before any routing rules (e.g. the rules you have that route things to index.php. So your htaccess file needs to look something like this:

# 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]

Upvotes: 6

Related Questions