Answer the question
In order to leave comments, you need to log in
htaccess - problems with 301 redirects with GET parameters, what am I doing wrong?
Urls have changed on the site and you need to make 301 redirects to the old ones.
It was my-site.ru/catalog/?branch=3855
It became my-site.ru/catalog/3855/
Tried various variations, ala:
RewriteRule ^catalog/?branch=([0-9]+)$ catalog/$1/ [R=301,L]
RewriteCond %{QUERY_STRING} ^[?]?branch=(.*)[&|$] [NC]
RewriteRule /catalog/ my-site.ru/catalog/%1/ [R=301 ,L]
RewriteCond %{QUERY_STRING} ^branch=([^&]+)
RewriteRule ^.*$ my-site.ru/catalog/%1/ [R=301]
didn't work...
Any Ideas?
Answer the question
In order to leave comments, you need to log in
In short, I was tormented in the end and I did it at the PHP level :)
if (strpos($_SERVER['REQUEST_URI'], '/catalog/?branch=') !== false)
{
header("HTTP/1.1 301 Moved Permanently");
header("Location: www.aleshka.by/catalog/ "".str_replace("/catalog/?branch=","",$_SERVER['REQUEST_URI'])."/");
exit();
}
but still, for the future, I would like to know how to implement this at the mod rewrite level
Try this option:
RewriteCond %{QUERY_STRING} ^branch=([0-9]+)
RewriteRule ^(.*)$ http://cv.local/$1%1/? [R=301,L]
Try like this:
RewriteCond %{QUERY_STRING} branch=(.*)$ [NC]
RewriteRule ^(.*) /? [R=301,L]
RewriteRule ^/catalog/\?branch=([0-9]+)$ /catalog/$1/ [R=301,L]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question