Claudiu Creanga
Claudiu Creanga

Reputation: 8366

Exclude subdomain from 301 redirect

I am trying to exclude the halcyondaysws subdomain from all my 301 redirects but can't manage it. I tried it like this:

RewriteCond %{HTTP_HOST} ^halcyondaysws\.maindomain\.net
RewriteRule .* - [S=7]
Redirect 301 /enamels.html http://www.halcyondays.co.uk/enamels/christening-nursery.html

and this

RewriteCond %{HTTP_HOST} ^(www\.)?maindomain\.com$ [NC]
RewriteRule /enamels.html http://www.maindomain.co.uk/enamels/christening-nursery.html [L,R=301]

But it doesn't work. We are using only one .htaccess file.

Upvotes: 1

Views: 826

Answers (1)

anubhava
anubhava

Reputation: 784878

To exclude a particular domain use this negation based condition:

RewriteCond %{HTTP_HOST} !^halcyondaysws\.maindomain\.net$ [NC]
RewriteRule ^enamels\.html$ http://www.maindomain.co.uk/enamels/christening-nursery.html [L,R=301,NC]

And test this after clearing browser cache.

Please understand this is not really excluding a sub-directory. Since your rule is targeting /enamels.html hence there is no need to exclude a sub-directory.

Upvotes: 2

Related Questions