Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So what I have at the moment (for each domain) is this

<VirtualHost *:80> 

  ServerAlias *

  DirectoryIndex index.php index.html
  VirtualDocumentRoot /srv/www/


But I'd like to save having to ever duplicate this for another domain by doing something like this

<VirtualHost *:80> 

  ServerName *
  ServerAlias *

  DirectoryIndex index.php index.html
  VirtualDocumentRoot /srv/www/%2+/public_html/%0


%2+ being all but the subdomain. Is this even possible…

share|improve this question

As long as you'd only have single-level subdomains, then that should work. If you want to serve all your pages via mod_vhost_alias, just take the VirtualDocumentRoot line out of the <VirtualHost> directives, and eliminate all your <VirtualHost> directives.

You don't need to specify the wildcard ServerName. It requires a FQDN anyway, so you can't use one anyway. Similarly with ServerAlias, since VirtualDocumentRoot is taking care of finding the right places to serve pages from, it's not necessary to use since the Host: header will be processed dynamically.

Reading the docs on mod_vhost_alias and Dynamically configured mass virtual hosting should help clear up any remaining confusion.

share|improve this answer

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.