I have a default .htaccess file that comes with drupal. In order to redirect externally linked pages from the old website to the new one I usually use statements like
Redirect /foo http://www.example.com/bar
This works as expected.
But the statement is totally ignored when looking like
Redirect /index.php?x=y http://www.example.com
and the request runs through the mod_rewrite rules from Drupal at the end of the .htaccess file.
Do you know what is the problem?
Problem
Redirect
does not match URL parameters, it will only match the PATH of a url.Solution
You CAN match the
QueryString
variable withRewriteCond
andRewriteRule
. Here is a working (but untested) snippet that you can try:You should note a few things about this:
RewriteCond
line is really a regex (regular expression), so you will have to escape any special characters you add to it (such as punctuation), and the first?
is omitted, but any further URL parameters with have to include the&
(RewriteCond %{QUERY_STRING} x=y&a=b
).Redirect
, because I specified the HTTP status code (a HTTP 301 Redirect, which is permanent).Credits