Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I set up a subdomain test.example.com and got it running, but now when I go to example.com, it points to test.example.com's directory. In other words, instead of going to /var/www/html it points to /var/www/test

I haven't altered httpd.conf other than adding this at the very bottom for the subdomain:

NameVirtualHost *:80

<VirtualHost *:80>
    ServerName www.test.example.com
    ServerAlias test.example.com
    DocumentRoot "/var/www/test/"

How can I fix httpd.conf so the normal domain points to /var/www/html and the subdomain continues to point to /var/www/test ?


share|improve this question

2 Answers 2

up vote 1 down vote accepted

Because when using virtual hosting, the "main host goes away". See http://httpd.apache.org/docs/2.2/vhosts/name-based.html , specifically the note "Main host goes away".

So, in your case, simply duplicate your VirtualHost container and configure it for a ServerName of www.example.com with a DocumentRoot of /var/www/html .

share|improve this answer
Thanks, that's all it needed! –  user1062058 Sep 25 '12 at 12:53

If this is the only vhost that you have configured then this is expected behaviour. Apache will serve up the requested domain or the default domain. Without an explicit default/catch-all domain the first vhost that apache processes is served.

If you want to serve up example.com you need to create a vhost for it

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot "/var/www/"

and then restart the httpd service.

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.