1

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…

Stefan Lasiewski
  • 23,667
  • 41
  • 132
  • 186
user75734
  • 11
  • 2

1 Answers1

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.

afrazier
  • 700
  • 4
  • 7