ddbruce
ddbruce

Reputation: 23

Need to redirect only root of domain, not any subdirectories

I currently have this:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com[/]? [NC]
RewriteCond %{HTTP_HOST} !^example.com/.+ [NC]
RewriteRule (.*) http://testsite.com [R=302,L]

It's not working too well. I need to redirect the root http://example.com, with or without a trailing slash, but no subdirectories http://example.com/sub, again, with or without a trailing slash, should be redirected.

Upvotes: 2

Views: 1024

Answers (1)

anubhava
anubhava

Reputation: 785146

You can use this rule:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^/?$ http://testsite.com [R=302,L]

Upvotes: 1

Related Questions