Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

<VirtualHost *:80> 

  ServerName exmaple.com
  ServerAlias *.example.com

  DirectoryIndex index.php index.html
  VirtualDocumentRoot /srv/www/example.com/public_html/%0

</VirtualHost>

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

</VirtualHost>

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

share|improve this question

1 Answer 1

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

 
discard

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.