dialogik
dialogik

Reputation: 9552

Forward non-www to www except for specific subdomain

I am routing all non-www requests to the www-domain by using this RewriteCond and RewriteRule:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.mydomain.tld/$1 [R=301,L]

But there is one certain subdomain that I want to exclude, e.g. blog.mydomain.tld. How do I have to modify my condition and rule in order to achieve this?

Upvotes: 1

Views: 52

Answers (2)

Lepanto
Lepanto

Reputation: 1413

Did you try adding

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

Upvotes: 1

anubhava
anubhava

Reputation: 785531

You can just add that subdomain in regex of your RewriteCond:

RewriteEngine On

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

Upvotes: 2

Related Questions