Virtual Host 2 Without www redirects to virtual host 1

Xeno picture Xeno · Aug 22, 2012 · Viewed 8k times · Source

my httpd.conf looks like this:

NameVirtualHost *:80

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

<VirtualHost *:80>
    DocumentRoot /var/www/host1.com/subdomain
    ServerName   subdomain.host1.com
    ServerAlias  www.subdomain.host1.com
</VirtualHost>

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

So, everything works like it should except:

host2.com shows /var/www/host1.com/

whereas

www.host2.com shows /var/www/host2.com/

I'm pretty sure this is an Apache config problem, but I can't figure it out. Any help??

Answer

sumous picture sumous · Aug 23, 2012

try in this way

DocumentRoot /var/www/host2.com
ServerName   www.host2.com
ServerAlias  *.host2.com