jacquesseite
jacquesseite

Reputation: 525

Regex url redirect in apache

i want to redirect pages in apache, so i tried this :

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteRule ^/?page_id=671 http://letempspourtoit.fr/news [L,R=301]

</IfModule>

but it just redirect to the home page. So i tried to escape the question mark like this :

RewriteRule ^/\?page_id=671 http://letempspourtoit.fr/news [L,R=301]

no success...

Any hint greatly appreciated!

Upvotes: 2

Views: 580

Answers (1)

Andrea Corbellini
Andrea Corbellini

Reputation: 17751

RewriteRule works on URL-paths, and query strings are not considered part of the path. You need a RewriteCond on QUERY_STRING:

RewriteCond %{QUERY_STRING} ^page_id=671$
RewriteRule ^/$ http://letempspourtoit.fr/news [L,R=301]

As you can see, the path for the RewriteRule is /.

Your RewriteRule worked for URLs like http://host/%3Fpage_id=671, that is: URLs with a %-encoded question mark.

Upvotes: 1

Related Questions