Page 1 of 1

OC 2.3, can't get htaccess 301 redirects to work

Posted: Sat Mar 21, 2020 12:13 pm
by takayuki
Hi,

I'm trying to do a simple 301 redirect via htaccess with my Opencart 2.3 site.

old url: http://domain.com/PokPlushToy/PlushToys/ChikoPlush
the url I want to redirect to: https://domain.com/PokPlushToy


Here's my rewrite rule:

Code: Select all

RewriteRule ^PokPlushToy/PlushToys/ChikoPlush$ index.php?route=category/PokPlushToy [R=301,NC,L]
But this ain't werkin. It results in this:

https://domain.com/PokPlushToy?_route_= ... ChikoPlush

thanks for any help here.

PS. my rule is before this rule:
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

but the url is still getting fouled.

Dave

Re: OC 2.3, can't get htaccess 301 redirects to work

Posted: Sat Mar 21, 2020 6:42 pm
by uksitebuilder
Please post full .htaccess content.

Order of commands / rules is important in .htaccess

Re: OC 2.3, can't get htaccess 301 redirects to work

Posted: Sat Mar 21, 2020 9:11 pm
by takayuki
Thanks for the reply. Here's the full file

Code: Select all

# SEO URL Settings
RewriteEngine On

RewriteBase /
RewriteRule ^sitemap.xml$ index.php?route=extension/feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=extension/feed/google_base [L]
RewriteRule ^system/download/(.*) index.php?route=error/not_found [L]

#heres the one that doesnt work...
RewriteRule ^PokPlushToy/PlushToys/ChikoPlush$ https://domain.com/PokPlushToy [R=301,NC,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]

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

RewriteCond %{QUERY_STRING} ^route=common/home$
RewriteRule ^index\.php$ https://domain.com? [R=301,L]

RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$  https://domain.com/$1 [L,R=301]

Re: OC 2.3, can't get htaccess 301 redirects to work

Posted: Sun Mar 22, 2020 6:28 am
by uksitebuilder

Code: Select all

# SEO URL Settings
RewriteEngine On
RewriteBase /

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

RewriteCond %{QUERY_STRING} ^route=common/home$
RewriteCond %{REQUEST_METHOD} !^POST$
RewriteRule ^index\.php$ https://domain.com? [R=301,L]

RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://domain.com/$1 [L,R=301]

RewriteRule ^sitemap.xml$ index.php?route=extension/feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=extension/feed/google_base [L]
RewriteRule ^system/download/(.*) index.php?route=error/not_found [L]

#heres the one that doesnt work...
RewriteRule ^PokPlushToy/PlushToys/ChikoPlush$ https://domain.com/PokPlushToy [R=301,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]
Other than the above, I cannot see why it would not work unless you have some kind of SEO URL modification installed

Re: OC 2.3, can't get htaccess 301 redirects to work

Posted: Sun Mar 22, 2020 8:54 am
by takayuki
thanks for your help, UKsitebuilder. unfortunately, i still get the wonky URL with the route=blahblah tacked on which 404s it.

I think you are right, there has to be another variable affecting things. it *should* work.