Skip to main content
1 of 2
John P Bloch
  • 11k
  • 37
  • 46

I'll use my own site's virtual host file as an example. This is all in one file:

# Virtual host for the subdomain first
<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName drupal.johnpbloch.com
    # Note that the document root and all other paths are different from the domain's primary virtual host below.
    DocumentRoot /path/to/subdomain/directory/htdocs/
    ErrorLog /path/to/subdomain/directory/logs/error.log
    CustomLog /path/to/subdomain/directory/logs/access.log combined
    <Directory /path/to/subdomain/directory/htdocs/>
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>
# Virtual host for the main site next
<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName johnpbloch.com
    ServerAlias www.johnpbloch.com
    ServerAlias *.johnpbloch.com
    DocumentRoot /path/to/main/site/directory/htdocs/
    ErrorLog /path/to/main/site/directory/logs/error.log
    CustomLog /path/to/main/site/directory/logs/access.log combined
    <Directory /path/to/main/site/directory/htdocs/>
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

That doesn't have to all be in one file; the important part is that Apache loads the more specific virtual host first. That means any virtual hosts with no wildcards in any ServerAlias values must be loaded before any virtual hosts with those wildcard values.

There is no value, no setting, nothing you could possible do with, in or around WordPress that could possibly solve your problem. By the time the request has reached WordPress, it's too late. Apache has already loaded the virtual hosts, already resolved the hosts, and will always route the traffic the way it does. If the traffic is getting to WordPress when it shouldn't be that is a server configuration issue. Not WordPress.

John P Bloch
  • 11k
  • 37
  • 46