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
/product/New-Product-Name?id=123&t=12345
.
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
/product/New-Product-Name
I'm imagining there's a better way to do this using RewriteMap
, but this might do for a one-off.