Forum Moderators: phranque

Message Too Old, No Replies

Help with HTACCESS file on a wildcard DNS enabled domain

301 redirect all possible subdomains EXCEPT a certain few (legit ones)

         

rollinj

8:12 am on Sep 1, 2006 (gmt 0)

10+ Year Member



I have the following htaccess code which will permanently 301 redirect any subdomain to my domain:

RewriteEngine On
RewriteCond %{HTTP_HOST} \.DOMAIN\.com$ [NC]
RewriteRule ^(.*)$ [DOMAIN.com...] [R=301,L]

This was fine while i kept my website on the main domain...

I now need to use certain subdomains (simply not 301 redirecting them) whilst still redirecting any subdomains I'm not using.

Can anyone help me out with a snippet of code to exclude say xx.domain.com and #*$!x.domain.com from the 301 redirect above?

Your help is much appreciated!

jdMorgan

12:40 pm on Sep 1, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



All you need is the NOT operator -- "!"

RewriteCond %{HTTP_HOST} !^xx\.example\.com

Jim

rollinj

7:13 pm on Sep 1, 2006 (gmt 0)

10+ Year Member



Thanks a million Jim! I just tried it out and it works great!

Your help has been greatly appreciated by me and I'm sure the few hundred other people with this same problem in the future!