I
I
Ivan Volkov2012-08-01 17:34:38
PHP
Ivan Volkov, 2012-08-01 17:34:38

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

5 answer(s)
I
Ivan Volkov, 2012-08-02
@oOLokiOo

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

D
dds, 2012-08-02
@dds

Try this option:

    RewriteCond %{QUERY_STRING} ^branch=([0-9]+)
    RewriteRule ^(.*)$ http://cv.local/$1%1/? [R=301,L]

I
ilyautkin, 2012-08-01
@ilyautkin

Try like this:

RewriteCond %{QUERY_STRING} branch=(.*)$ [NC]
RewriteRule ^(.*) /? [R=301,L] 

V
Vladimir Dubrovin, 2012-08-01
@z3apa3a

RewriteRule ^/catalog/\?branch=([0-9]+)$ /catalog/$1/ [R=301,L]

T
tegrato, 2019-11-28
@tegrato

Here are the options for 301 redirects with parameters: https://skalolaskovy.ru/joomla/500-htaccess-301-re...
The task, however, is a little different, but the principle can be used and manually register all redirects, without a universal mask.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question