Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've got a rewrite like this:

RewriteRule /products.php?id=123&t=12345 /product/New-Product-Name

If I turn on RewriteLogging, and turn the level up, I get the following:

applying pattern '/products.php?id=123&t=12345' to uri '/products.php'

Why is the full uri (including querystring) not being looked at?

share|improve this question
up vote 1 down vote accepted

From the mod_rewrite docs:

Note: Query String

The Pattern will not be matched against the query string. Instead, you must use a RewriteCond with the %{QUERY_STRING} variable. You can, however, create URLs in the substitution string, containing a query string part. Simply use a question mark inside the substitution string, to indicate that the following text should be re-injected into the query string. When you want to erase an existing query string, end the substitution string with just a question mark. To combine a new query string with an old one, use the [QSA] flag.

In short, you'll need to use a combination of RewriteCond and RewriteRule; maybe something like:

RewriteCond %{QUERY_STRING} ^id=123&t=12345$
RewriteRule /products.php /product/New-Product-Name

Update: I tested this, and it works as I described. It redirects to

If you want the query string ?id=123&t=12345 to be removed, add a ? to the RewriteRule, like:

RewriteRule /products.php /product/New-Product-Name?

which will redirect to

I'm imagining there's a better way to do this using RewriteMap, but this might do for a one-off.

share|improve this answer

Your Answer


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.