Written by Sean Behan on Sun Jun 17th 2012

Set your ServerAlias directive to *.domain.tld - Here is a quick example.

<VirtualHost>
  ServerName example.com
  ServerAlias *.example.com
  DocumentRoot /var/www/path/to/site
</VirtualHost>
Now everything.example.com and anything.example.com, even though you didn't explicitly set them, will map to the /var/www/path/to/site directory on the filesystem. The wildcard character "*" matches any string.

You'll also need to set up a wildcard DNS "A" record. An "A" record, short for address, maps a subdomain to an IP address. If your running your own DNS, such as BIND, I assume you can handle this part on your own. If you use a hosted DNS provider like register.com or namebargain.com, you can make an A record through an admin control panel.


Tagged with..
#serverAlias #VirtualHost #Programming

Just finishing up brewing up some fresh ground comments...