I need to write two redirects:
- From
https://site.ru/dveri
tohttps://anothersite.ru/dveri-iz-dereva/
- From
https://site.ru/dveri?start=14
tohttps://anothersite.ru/blog/
I wrote two rules in htaccess:
#1
RewriteCond %{THE_REQUEST} \s/ dveri[?\s/] [NC]
RewriteRule ^ https://anothersite.ru/dveri-iz-dereva/ [L,R=301]
#2
RewriteCond %{THE_REQUEST} \s/ dveri[?\s/] [NC]
RewriteRule ^.*$ https://anothersite.ru/blog/? [L,R=301]
Result:
link https://site.ru/dveri
redirect correctly to https://anothersite.ru/dveri-iz-dereva/
link https://site.ru/dveri?start=14
redirects incorrectly to https://anothersite.ru/dveri-iz-dereva/?start=14
CodePudding user response:
The two rules you wrote are the same. Try this for the second
RewriteCond %{THE_REQUEST} /dveri\?start=14$
RewriteRule ^ https://anothersite.ru/blog/? [L,R=301]
CodePudding user response:
My experienced collegue helped me with this:
RewriteCond %{THE_REQUEST} \s/ dveri[?\s/] [NC]
RewriteCond %{QUERY_STRING} ^start=14$
RewriteRule ^.*$ https://anothersite.ru/blog/? [L,R=301]
RewriteCond %{THE_REQUEST} \s/ dveri[?\s/] [NC]
RewriteRule ^ https://anothersite.ru/dveri-iz-dereva/ [L,R=301]
CodePudding user response:
RewriteCond %{THE_REQUEST} \s/ dveri[?\s/] [NC] RewriteCond %{QUERY_STRING} ^start=14$ RewriteRule ^.*$ https://anothersite.ru/blog/? [L,R=301] RewriteCond %{THE_REQUEST} \s/ dveri[?\s/] [NC] RewriteRule ^ https://anothersite.ru/dveri-iz-dereva/ [L,R=301]
If these directives are placed at the top of the root .htaccess
file then these can be simplified to:
RewriteCond %{QUERY_STRING} ^start=14$
RewriteRule ^dveri/?$ https://anothersite.ru/blog/ [NC,QSD,R=301,L]
RewriteRule ^dveri/?$ https://anothersite.ru/dveri-iz-dereva/ [NC,R=301,L]