skip to Main Content

I need to write two redirects:

  1. From
    https://site.ru/dveri to https://anothersite.ru/dveri-iz-dereva/
  2. From
    https://site.ru/dveri?start=14 to https://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 redirects 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

3

Answers


  1. Chosen as BEST ANSWER

    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]
    

  2. 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]
    
    Login or Signup to reply.
  3. 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]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search