skip to Main Content

how do I redirect multiple url to another one url
I have tried but its not working

RewriteCond  %{HTTP_HOST} ^sub.domain.to/q1$ [NC,OR]
RewriteCond  %{HTTP_HOST} ^sub.domain.to/q2$ [NC,OR]
RewriteCond  %{HTTP_HOST} ^sub.domain.to/q3$ [NC,OR]
RewriteCond  %{HTTP_HOST} ^sub.domain.to/q4$ [NC,OR]
RewriteCond  %{HTTP_HOST} ^sub.domain.to/q5$ [NC]
RewriteRule ^(.*)$ https://sub.domain.to/full-q [R=301,L]

2

Answers


  1. Chosen as BEST ANSWER

    ok it worked when I added %{REQUEST_URI}

    so this worked

    RewriteCond  %{HTTP_HOST}%{REQUEST_URI} ^sub.domain.to/q1$ [NC,OR]
    RewriteCond  %{HTTP_HOST}%{REQUEST_URI} ^sub.domain.to/q2$ [NC,OR]
    RewriteCond  %{HTTP_HOST}%{REQUEST_URI} ^sub.domain.to/q3$ [NC,OR]
    RewriteCond  %{HTTP_HOST}%{REQUEST_URI} ^sub.domain.to/q4$ [NC,OR]
    RewriteCond  %{HTTP_HOST}%{REQUEST_URI} ^sub.domain.to/q5$ [NC]
    RewriteRule ^(.*)$ https://sub.domain.to/full-q [R=301,L]
    

  2. The HTTP_HOST server variable contains the value of the Host HTTP request header, ie. the hostname only. This does not contain the URL-path (ie. /q1 and /q2 in your example).

    The RewriteRule pattern matches against the URL-path.

    Try the following instead:

    RewriteCond %{HTTP_HOST} ^sub.domain.to [NC]
    RewriteRule ^(q1|q2|q3|q4|q5)$ https://%{HTTP_HOST}/full-q [NC,R=301,L]
    

    Or, use the REQUEST_URI server variable in a condition, which contains the full URL-path. For example:

    RewriteCond %{HTTP_HOST} ^sub.domain.to [NC]
    RewriteCond %{REQUEST_URI} ^/q1$ [NC,OR]
    RewriteCond %{REQUEST_URI} ^/q2$ [NC,OR]
    RewriteCond %{REQUEST_URI} ^/q3$ [NC,OR]
    RewriteCond %{REQUEST_URI} ^/q4$ [NC,OR]
    RewriteCond %{REQUEST_URI} ^/q5$ [NC]
    RewriteRule ^ https://%{HTTP_HOST}/full-q [R=301,L]
    

    Test with a 302 (temporary) redirect to avoid potential caching issues and only change to a 301 (permanent) redirect – if that is the intention – once you have confirmed this works as intended.

    You will need to clear your browser cache before testing.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search