Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 ^/$

...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
up vote 0 down vote accepted

Think you have to use mod_rewrite

RewriteCond %{THE_REQUEST} ^GET\ /\ HTTP
RewriteRule / [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 / [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 / [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

Your Answer


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.