Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.