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

My Apache virtual host configuration only works for www.domain.com but not domain.com. Can you tell me why?

<VirtualHost *:80>
        DocumentRoot /var/www/stable/

        <Directory />
                Options FollowSymLinks Indexes +ExecCGI
                AllowOverride All
                Order allow,deny
                Allow from all
                AddHandler fcgid-script .php
                FCGIWrapper /var/www/php-fcgi-scripts/stable/php-fcgi-starter .php

        ServerName www.domain.com
        ServerAlias domain.com www.domain.com

Thank you.

share|improve this question
add comment

6 Answers

up vote 0 down vote accepted

Maybe somewhere else in your Apache configuration there is another or ServerName/ServerAlias for 'domain.com'?

share|improve this answer
I did a grep on "domain.com" but found nothing wierd in either /etc/ or /var/. –  Christoffer Mar 1 '10 at 15:24
Ok, it wasn't really any other option but a standard site was defined which was overriding my options. Once I removed it all is well. –  Christoffer Mar 1 '10 at 15:28
add comment

Have you specified NameVirtualHost *:80?

See: http://httpd.apache.org/docs/2.2/vhosts/name-based.html#using

share|improve this answer
add comment

Hmmm, are you sure your DNS answers the same for domain.com and www.domain.com? To make sure it is the case, a simple check might help:

nslookup domain.com
nslookup www.domain.com

I've been sometimes struggling for nothing since the two A records would not return the same thing. If or once they are pointing on the same IP then Apache conf can be tuned but this is what I use and it works:

ServerName domain.com
ServerAlias www.domain.com

Don't forget to reload Apache (no need to restart it completely and disconnect clients):

/etc/init.d/apache2 reload

(or similar)

Good luck!

share|improve this answer
They return exactly the same on nslookup. –  Christoffer Mar 1 '10 at 15:04
add comment

replace ServerAlias domain.com www.domain.com with ServerAlias domain.com. do www.domain.com and domain.com have the same ip address/ips that are configured for this host?

share|improve this answer
add comment

It should probably be:

ServerName domain.com
ServerAlias www.domain.com

Make sure to restart apache as well...

share|improve this answer
add comment

Have you got host entries setup for www.domain.com but not domain.com ? As it sounds like its not resolving as your apache configuration looks good. Can you ping each address and ensure its going to the correct location?

share|improve this answer
When I visit domain.com I get to the standard Apache index file in /var/www/index.html... But www.domain.com points to /var/www/stable/index.php –  Christoffer Mar 1 '10 at 15:07
add comment

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.