Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

I also use mod_rewrite to rewrite to

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

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

Now, the problem is that whenever I lookup it redirects me to

I tried adding another RewriteCond:

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

But it didn't help...

Anyone has some ideas?

share|improve this question
Is the CNAME record for pointing to either or Or is it pointing to some other domain entirely? If I understand your description correctly subdomain should never get to the mod_rewrite stuff. That means the problem is with the dns. –  matthew Feb 6 '11 at 2:04
the CNAME record is pointing to another domain entirely –  Tom Feb 6 '11 at 2:07
I just ran dig - the answer was correct from the dns –  Tom Feb 6 '11 at 2:17
If you turn on rewrite logging, what do you see in the log file? –  larsks Feb 6 '11 at 2:37
Do you have any /etc/hosts entries that may be causing problems? Try the command getent hosts –  BillThor Feb 6 '11 at 5:11

2 Answers 2

Maybe a redirect is happening in the web application.

  • Try download static file(css,js,jpg,...) from
  • Use RewriteLog and RewriteLogLevel Directive for debug
share|improve this answer
up vote 0 down vote accepted

matthew was right, the request should never get to mod_rewrite with proper dns alias configuration. The problem was in a simple DNS record syntax mistake made accidentally when typing. It's now taken care of and working properly :)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.