301 redirect OpenCart - .htaccess

everybody
How does it possible to make 301 redirect from url like
/index.php?_car_=product&filtr[make]=6
To
/catalog/make/audi
I try to use the following code, but it doesn't work
RewriteCond %{THE_REQUEST} ^GET\ /index\.php\?_car_=product&filtr[make]=6 [NC]
RewriteRule ^index.php$ /catalog/make/audi? [R=301,L]

Your problem is that [ and ] are regex special chars, You need to escape special chars by using a backslash to match them literally,try :
RewriteEngine on
RewriteCond %{THE_REQUEST} ^GET\ /index\.php\?_car_=product&filtr\[make\]=6 [NC]
RewriteRule ^ /catalog/make/audi? [R=301,L]

Related

htaccess redirect 301 keeping id

i would like redirect permanent 301 :
https://www.toto.com/index.php?id=4
to
https://www.toto.com/?id=4
this could be fine ? =>
RewriteRule index.php?id=([0-9]+)$ /?id=$1 [L,NC,R=301]
Thanks !
You cannot match Query String i.e. ? and part after that in RewriteRule.
You can use following rule to remove index.php from all paths but keep query string:
RewriteEngine On
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteCond %{REQUEST_URI} ^(.*/)index\.php$ [NC]
RewriteRule ^ %1 [L,R=301,NE]

How can I exclude a request URI from redirection?

I want to redirect all page requests to another domain, but exclude some request URI which I want to redirect separately. So I have tried something like this:
RewriteCond %{REQUEST_URI} !^/index.php?id=132$ [NC,OR]
RewriteCond %{REQUEST_URI} !^/index.php?id=133$ [NC]
RewriteRule .* https://new-domain.com/? [R=301,L]
Redirect 301 /index.php?id=132 https://new-domain.com/example
Redirect 301 /index.php?id=133 https://new-domain.com/example2
But this is not working, can someone tell me what is wrong?
%{REQUEST_URI} variable or Redirect directive doesn't match query string.
You can use it like this with a better regex:
RewriteCond %{THE_REQUEST} !/index\.php\?id=13[23][&\s] [NC]
RewriteRule ^ https://new-domain.com/? [R=301,L]
RewriteCond %{THE_REQUEST} /index\.php\?id=132[&\s] [NC]
RewriteRule ^ https://new-domain.com/example? [L,R=301]
RewriteCond %{THE_REQUEST} /index\.php\?id=133[&\s] [NC]
RewriteRule ^ https://new-domain.com/example2? [L,R=301]
Also note use of ? in target URL to discard previous query string.

htaccess using RewriteRule and RewriteCond to redirect specific url

I have to redirect (301) from
http://domain/index.php to
http://domain/
I've done it with following rules:
RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ /$1 [R=301,L]
Ok. it works, BUT I do NOT want to allow redirect from urls like:
http://domain/asd/index.php
I've tried to change condition like:
RewriteCond %{THE_REQUEST} ^/index.php
RewriteCond %{THE_REQUEST} ^/index.php
but no success.
So, how to redirect ONLY from http://domain/index.php to http://domain/
ps: I do not want to use REDIRECT command
Try this:
RewriteRule ^index.php$ / [R=301,L]
You can use the following rule :
RewriteEngine on
RewriteCond %{THE_REQUEST} \s/index\.php\s [NC]
RewriteRule ^ / [L,R]

.htacces redirect with special signs

Need help ;)
How to redirect this link?
mydomain.com/selbständige?catid=141&id=141:kredit-für-selbstständige-ohne-schufa
Tested with:
RewriteCond %{QUERY_STRING} ^(.+&)?selbständige?catid=141(&.+)?$
RewriteRule ^/$ http://test.com? [R=301,L]
RewriteCond %{QUERY_STRING} ^(.+&)selbst%E4ndige?catid=141(&.+)?$
RewriteRule ^/$ http://test.com? [R=301,L]
redirect 301 "/selbständige?catid=141&id=141:kredit-für-selbstständige-ohne-schufa" http://test.com
...and so on.
No normal workflow works.
Try :
RewriteEngine on
RewriteCond %{THE_REQUEST} /selbst.+ndige\?catid=141&id=141:kredit-f.+r-selbstst.+ndige-ohne-schufa [NC]
RewriteRule ^ http://test.com? [L,R]
I used .+ to match against special chars in the uri.

301 Redirect for URLs with % percentage mark on htacess

I neee to redirect
http://www.example.com.au/recipes/recipe.aspx?name=91-Sunflower%20Crackers
to https://www.example.com.au/recipes/
I followed so many posts but this is not redirecting at all.
This is my code
RewriteCond %{QUERY_STRING} ^name=91-Sunflower%20Crackers$
RewriteRule ^/recipes/recipe\.aspx?$ /recipes/? [NE,L,R]
What is the error here ?
This rule should work:
RewriteCond %{QUERY_STRING} "^name=91-Sunflower(\s|%20)Crackers$" [NC]
RewriteRule ^recipes/recipe\.aspx?$ /recipes/? [NC,L,R]
No leading slash in RewriteRule and use (\s|%20) in RewriteCond to match a whitespace.

Resources