I’ve been trying to make:
http://site.com/file.php?x=foo
redirect to:
http://newsite.com/something/completely/different/
Using the following:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^file\.php?x=foo$ http://newsite.com/something/completely/different/ [R=301,NC,L]
</IfModule>
But it doesn’t do anything (just loads same old page as if I never touched the htaccess).
Is there something I’m missing?
Thanks much for the help!
The
?at the end of.phpis making the lastpoptional (so.phpx=fooor.phx=foowould match). It’s not actually being considered a character in the match. Try escaping the?like:\?Edit:
For those wondering what the solution was:
The query string arguments aren’t passed to the string that
RewriteRulematches against. So you have to create aRewriteCondonQUERY_STRINGfirst, then match the url without arguments. E.g.:There’s probably/hopefully a better way to do this (since this
RewriteCondwould cascade down to other rules, which is annoying).