Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I want to redirect just the homepage of a Wordpress site but only if the original URL does not have any query strings on it. This works:

RedirectMatch 307 ^/$ http://www.consumerenergyreport.com/ticker

...but redirects URLs with queries. I tried:

RewriteCond ! %{QUERY_STRING}

...but that doesn't seem to work with RedirectMatch, only RewriteRule (go fig).

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

Think you have to use mod_rewrite

RewriteCond %{THE_REQUEST} ^GET\ /\ HTTP
RewriteRule / http://www.sod.com/ [R=307]

This will also mean it doesn't redirect POST requests to the home page as well. Not sure if thats what you wanted. But figured it was as it could imply parameters, like the query string.

If you wanted to also redirect HEAD requests

RewriteCond %{THE_REQUEST} ^(GET|HEAD)\ /\ HTTP
RewriteRule / http://www.sod.com/ [R=307]

And if you didn't want to use THE_REQEST then you can do it with two conditions

RewriteCond %{REQUEST_URI} =/
RewriteCond %{QUERY_STRING} =""
RewriteRule / http://www.sod.com/ [R=307]

Edit: RedirectMatch is not part of mod_rewrite. Its part of mod_alias, so completely independant of any rewrite conditions.

share|improve this answer
add comment

Your Answer

 
discard

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.