I'm establishing virtual hosts on two domain names. Various sub domain names get their own docroot.

<VirtualHost *:80>
        ServerName *.domain1.com
        VirtualDocumentRoot /var/www/domain1/%1/
</VirtualHost>
<VirtualHost *:80>
        ServerName *.domain2.com
        VirtualDocumentRoot /var/www/domain2/%1/
</VirtualHost>

Being able to access

should show

  • /var/www/domain2/www/

but rather it searches for

  • /var/www/domain1/www/

What's going wrong?

do this:

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

I want the ServerAlias option that udo pointed out to avoid one VirtualHost from catching everything. Do this:

<VirtualHost *:80>
        ServerName domain1.com
        ServerAlias *.domain1.com
        VirtualDocumentRoot /var/www/domain1/%1/
</VirtualHost>
<VirtualHost *:80>
        ServerName domain2.com
        ServerAlias *.domain2.com
        VirtualDocumentRoot /var/www/domain2/%1/
</VirtualHost>