I created a virtual host at my server to host multiple sites, but I got a few unexpected problems. One sites doesn't gets recognized by the server and is redirected to another domain on the server, another one just works without 'www' but the one with the 'www' gets also redirected to a different domain.

The code i use in vhost.conf is:

 <VirtualHost *:80>
  ServerName domain.com
  #ServerAlias www.domain.com domain.com
  DocumentRoot /var/www/vhosts/domain.com
  #ServerAdmin [email protected]

<Directory /var/www/vhosts/domain.com>
  AllowOverride All

It works fine on other domains on the same server. What did i do wrong and how can i fix it?

Thanks in advance!

  • 1
    Why do you have the ServerAlias line commented out? Commented Oct 22, 2015 at 19:31

1 Answer 1


You need to remove the commented out server alias declaration. By commenting it out the only domain string that would use this vhost file is domain.com. You will probably find that the domain that the www domain is being redirected to is in the default configuration for the server where all connections not specifically handled by vhost files are directed to.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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