To match a query string, a condition must be added to the RewriteRule
. This is done by putting RewriteCond
directives before the corresponding rule. In the following example we dynamically internally rewrite an old url to a new url.
RewriteCond %{QUERY_STRING} ^name=([^&]*)$
RewriteRule ^oldscript\.php$ newscript.php?username=%1 [L]
Please note that to match the literal dot, we have to escape it with a slash. %1
is replaced with the first capture group of the previous condition. In this case it is replaced by whatever is matched by ([^&]*)
.