If you want to match the query string you need to use mod_rewrite and check the QUERY_STRING server variable in a RewriteCond
directive. mod_alias directives (ie. Redirect
and RedirectMatch
match the URL-path only, not the query string).
For example, to redirect http://example.com/?bloginfo=racing
to http://example.com/racing
you could do something like the following:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^bloginfo=racing$
RewriteRule ^$ /racing? [R=302,L]
The trailing ?
on the substitution is required in order to remove the query string from the request, otherwise, it is passed through to the target URL. Alternatively, use the QSD
flag on Apache 2.4+
Change the 302 (temporary) to 301 (permanent) if this is intended to be permanent and only when you are sure it's working OK (to avoid caching problems).
To make this more generic and redirect /?bloginfo=<something>
to /<something>
then you can do something like the following:
RewriteCond %{QUERY_STRING} ^bloginfo=([^&]+)
RewriteRule ^$ /%1? [R=302,L]
%1
is a backreference to the captured subpattern in the last match CondPattern.