Tohid Tohid - 1 month ago 25
Apache Configuration Question

301 redirection in opencart

I am using OpenCart 1.5.6 and I recently moved my store from a subdomain to the main domain. Now I'm trying to redirect some of the old static category pages to the actual opencart category/product pages.

Here is my .htaccess line:

Redirect 301 /old-category.html http://www.mydomain.com/my-new-category


This rule works fine for most of my URLs but for some of them it takes me to:

http://www.mydomain.com/my-new-category?route=old-category.html

Some people suggested to use RewriteRule instead or add a question mark in the end, I did try all that but nothing works !

I also tried putting my rules before and after the following block:

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]


Anyone has any idea ?

Answer

This should work:

RewriteEngine On

RewriteRule ^old-category\.html$ http://www.mydomain.com/my-new-category [L,NC,R=301]

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]

Make sure to test this in a new browser to avoid 301 caching issues.

Comments