DNS and mod_rewrite not-collaborating

Posted by ???? ????????? on Server Fault See other posts from Server Fault or by ???? ?????????
Published on 2011-02-06T01:54:26Z Indexed on 2011/02/06 7:27 UTC
Read the original article Hit count: 502

Filed under:
|
|
|

Hello,

I have added a CNAME record to my DNS on my CentOS server to redirect subdomain.mydomain.com to another server.

I also use mod_rewrite to rewrite mydomain.com to www.mydomain.com:

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

this is placed into .htaccess in the root public html directory

Now, the problem is that whenever I lookup subdomain.mydomain.com it redirects me to www.mydomain.com

I tried adding another RewriteCond:

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

But it didn't help...

Anyone has some ideas?

© Server Fault or respective owner

Related posts about dns

Related posts about centos