itsallwhite
itsallwhite

Reputation: 1

.htaccess rewrite add sub-domain exception (remove redirect)

I have checked previous questions, I believe this is quite simple but I can't seem to work it out.

In my .htaccess file I currently have

RewriteCond %{HTTP_HOST} !^www\.bodycleansediet\.com [NC]
RewriteRule ^(.*)$ http://www.bodycleansediet.com/$1 [R=301,L]

However this is causing a problem as it also redirecting any sub-domains (specifically au.bodycleansediet.com and ca.bodycleansediet.com) to www.bodycleansediet.com

I want them NOT be to be redirected so they can be viewed on their sub-domains.

I know I need to add an exception/re-write rule but I am not sure how to construct it.

Any advice on how to construct this?

Upvotes: 0

Views: 1342

Answers (1)

cristobal
cristobal

Reputation: 462

Should not something along the following lines work

RewriteCond %{HTTP_HOST} !^(www|ca|au)\.bodycleansediet\.com [NC]
RewriteRule ^(.*)$ http://www.bodycleansediet.com/$1 [R=301,L]

Since you are basically checking if not (www OR ca OR au) then do your redirect.

Upvotes: 1

Related Questions