Kyle Goslan
Kyle Goslan

Reputation: 10920

Opencart 301 Redirects

Having a problem with redirect in a .htaccess file on an Opencart store.

It seems that any URL with /index.php?_route_= isn't getting redirected.

For example, this works:

redirect /old-url-here http://example.com/new-url?

This doesn't:

redirect /index.php?_route_=some-url.asp http://example.com

Any idea or suggestions as to what might get this to work?

Upvotes: 0

Views: 809

Answers (2)

shadyyx
shadyyx

Reputation: 16055

Another thing is - apart from Jon's answer - that URLs like index.php?_route_=some-keyword are used/created only internally and only in case you have the SEO turned on. In this case, you click on a link with URL like http://yourstore.com/some-keyword and this URL is rewritten into index.php?_route_=some-keyword.

Therefore you shouldn't be creating URLs like that on your own nor try to redirect from them. If you need to redirect, catch the first SEO URL to redirect it.

We do not know where did you put your changes into the .htaccess file, but if you take a close look at this rewrite rule

RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

not only you'll find out it is the last rule there, but it also has this L switch which is telling Apache server that if this rule is matched, do a URL rewrite(, attach the query string [QSA] and) stop matching other rules [L] - this is the Last one.

If you need to redirect only a specific URL, do it the same way as redirect for sitemap.xml is done (for example) and place it before the last rewrite rule:

RewriteEngine On
RewriteBase /
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
# ...
# your new rule here - while the URL in the link is http://yourstore.com/some-url.asp
RewriteRule ^some-url.aspx$ index.php?route=some-folder/some-controller [L]
# ...
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

Upvotes: 0

Jon Lin
Jon Lin

Reputation: 143876

You can't match against the query string using mod_alias' Redirect directive. You'll need to use mod_rewrite, and if you use mod_rewrite, you're probably going to want to stop using mod_alias altogether.

Try:

RewriteEngine On
RewriteCond %{QUERY_STRING} route=some-url\.asp
RewriteRule ^index\.php$ http://example.com/

Upvotes: 1

Related Questions