apache - 301 Redirect for Query String on Root? -




i have tried multiple methods of trying redirect urls query string on root, example, if try match url http://example.com/?bloginfo=racing

redirect 301 "/?bloginfo=racing" http://example.com/racing 

or

redirectmatch 301 ^/?bloginfo=racing$ http://example.com/racing 

the condition never match. there method inside of .htaccess file write kind of redirect?

if want match query string need use mod_rewrite , check query_string server variable in rewritecond directive. mod_alias directives (ie. redirect , redirectmatch match url-path only, not query string).

for example, redirect http://example.com/?bloginfo=racing http://example.com/racing following:

rewriteengine on  rewritecond %{query_string} ^bloginfo=racing$ rewriterule ^$ /racing? [r=302,l] 

the trailing ? on substitution required in order remove query string request, otherwise, passed through target url. alternatively, use qsd flag on apache 2.4+

change 302 (temporary) 301 (permanent) if intended permanent , when sure it's working ok (to avoid caching problems).

to make more generic , redirect /?bloginfo=<something> /<something> can following:

rewritecond %{query_string} ^bloginfo=([^&]+) rewriterule ^$ /%1? [r=302,l] 

%1 backreference captured subpattern in last match condpattern.





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -