0

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).

Teddy
  • 5,134
  • 1
  • 22
  • 27

1 Answers1

0

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.

Sodved
  • 163
  • 5