Wildcard DNS and Dynamic Subdomains

In all my spare time (ha!), I've been working to wrap the Wild Birds Unlimited Map application with an enterprise application that will allow folks to design their own store locator. Developing my own Software as a Service solution has been a goal of mine for quite a few years, and this is a great opportunity.

There are two key features off the shelf that I wanted to put into the application that are turning out to be a huge challenge so I wanted to discuss them in the event you're ever looking to do the same. Both features are commonplace throughout applications, but I've come to find out that even though they're commonplace, many hosting providers don't actually support them!

My goal is to build a self-service application where the client can configure their own subdomain (http://subdomain.myapplicationdomain.com), or even apply their own subdomain (http://subdomain.yourdomain.com). In order for it to be self-service, it requires the ability to program the solution – but it accesses some domain name server configuration files that are off-limits with the majority of hosting accounts! The issue is support for Wildcard DNS, that is, to be able to point any subdomain to the domain of the server. In other words, test.domain.com or www.domain.com or any.domain.com all point to the same place. No matter what you write – it will work.

Outside of applications, this is actually a pretty nice feature to have enabled – even on your blog. It would allow anyone to write anything.yourdomain.com and bring them to yourdomain.com. You'd be surprised at how many bad links there are that point to your blog or web site. That could be missed traffic if the person doesn't recognize that it's an error with the link.

The process works by rewriting the subdomain to a querystring before the page is actually rendered by the webserver… so subdomain.domain.com actually gets interpreted by Apache servers as domain.com?what=subdomain through use of an htaccess file:

# Extract the subdomain part of domain.com
RewriteCond %{HTTP_HOST} ^([^\.]+)\.yourdomain\.com$ [NC]
# Check that the subdomain part is not www and ftp and mail
RewriteCond %1 !^(www|ftp|mail)$ [NC]
# Redirect all requests to a php script passing as argument the subdomain
RewriteRule ^.*$ http://www.yourdomain.com/%1 [R,L]

There's some additional information on the files you need to edit at V-nessa.net. Note that the files may not be located where specified depending on your hosting provider. My hosting provider actually is very supportive of folks meddling, but they warn that doing so may void customer support. As well as ‘hack at your own risk', they aren't going to reach out to help you, either.

I'm going to work on developing out the rest of the application rather than getting hung up on the subdomain development. I'm actually going to give CakePHP a shot to use as a framework for it!

Last note, I'm a bit of a hack on this stuff. I'm blessed with development teams at my work to figure this stuff out. On my own, I'm a little dangerous. Any feedback and help is appreciated!


  1. 1

    Very cool. I actually used my registrar’s name server with wildcard DNS when I was with SliceHost, and had Apache configured to serve unconfigured subdomains from the regular domains files.

    I was really intrigued to look at the CakePHP framework, but your link is dead 🙂

    CakePHP can be found at http://cakephp.ORG

    • 2

      I was thinking about going the registry route as well, Alex. That’s a great idea – probably the best way to handle this.

      Sorry about the dead link – it’s fixed now.

  2. 3

What do you think?

This site uses Akismet to reduce spam. Learn how your comment data is processed.