Aryeh Armon
Aryeh Armon

Reputation: 2185

url redirect exact match including params

i would like to make a 301 redirect and from an old website using the exact exact url with no extra parameters.

example:

/en-direct.php?page=7

to go to:

http://www.example.org/news/

and page:

/en-direct.php?page=8

to go to:

http://www.example.org/awesome-but-totally-different-page/

i used:

redirectMatch 301 ^/en-direct.php$ http://www.example.org/different-page/
redirectMatch 301 ^/en-direct.php?page=7$ http://www.example.org/news/
redirectMatch 301 ^/en-direct.php?page=8$ http://www.example.org/awesome-but-totally-different-page/

however: i get http://www.example.org/different-page/ every time with all the parameters from the redirect page (example - http://www.example.org/different-page?page=7 )

any help will be much appreciated.

Upvotes: 1

Views: 1616

Answers (1)

Jon Lin
Jon Lin

Reputation: 143916

In order to match against the query string, you need to use mod_rewrite:

RewriteEngine On

RewriteCond %{QUERY_STRING} ^page=7($|&)
RewriteRule ^en-direct\.php$ http://www.example.org/news/ [L,R=301]

RewriteCond %{QUERY_STRING} ^page=8($|&)
RewriteRule ^en-direct\.php$ http://www.example.org/awesome-but-totally-different-page/ [L,R=301]

RewriteCond %{QUERY_STRING} ^$
RewriteRule ^en-direct\.php$ http://www.example.org/different-page/ [L,R=301]

Upvotes: 2

Related Questions