0

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?

1 Answer 1

1

Problem

Redirect does not match URL parameters, it will only match the PATH of a url.

Solution

You CAN match the QueryString variable with RewriteCond and RewriteRule. Here is a working (but untested) snippet that you can try:

RewriteCond %{QUERY_STRING} x=y
RewriteRule ^index.php http://www.example.com [R=301]

You should note a few things about this:

  1. The 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).
  2. This method is equvilent to a Redirect, because I specified the HTTP status code (a HTTP 301 Redirect, which is permanent).

Credits

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .