Configuring Apache to work with wildcard subdomains
Configuring Apache to accept wilcard domains can be very useful. Having the wildcard domain go to a specific subdomain is even more so, so here's a short how to.
Step one is to set up your domain to accept wildcard domains. This is done by configuring the A record for your domain so that any hits to anything.yourdomain.com (and by anything, I mean *.yourdomain.com) go to the IP address you have assigned to your server. Permalink for this article http://mirror.magicode.org/content/Configuring_wildcard_subdomains_with_Apache
Step two is to configure Apache to accept *.yourdomain.com. This is typically done by editing httpd.conf like so:
This text was originally written for http://blog.magicode.org
That's the easy part, and if all you want is point example.yourdomain.com to www.yourdomain.com (or any other subdomain to www.yourdomain.com for that matter), you're done.
If you want to take it a step further, so that example.yourdomain.com points to www.yourdomain.com/example, you need to use Apache's Rewrite engine. It's a tricky beast, but let's give it a go.
Here's how you do it:
If you see this notice on any site other than magicode.org, it's probably been lifted without consent
All you have to do now is store the above in the file called .htaccess in the root of your public folder (or add it to the VirtualHost directive in httpd.conf) :).
