Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I can go to Fog Creek's web site, setup a new account, and they will instantly assign me a URL such as '' (where 'mycompany' is something I make up, as opposed to some value assigned by Fog Creek). I can do the same type of thing with Beanstalk and many other vendors. I have been Googling around trying to figure out exactly how this works.

1: In the above example, is '' set up in DNS in some special way other than how one would setup a vanilla '' domain?

2: Assuming Fog Creek uses Tomcat (which I am sure is NOT true, but pretend it is) would they be likely to have created a tomcat/webapps/mycompany subdirectory on their server? Or is there some simpler way to handle this?

I'm obviously not a DNS or TC wizard. Any insight appreciated. Happy New Year!

share|improve this question

migrated from Jan 4 '10 at 1:47

This question came from our site for professional and enthusiast programmers.

This is what's called a wildcard subdomain (in the dns) which is then handled using url rewriting.

A wildcard subdomain looks like this:

*.domain.tld.      IN  A

Then you can set apache to accept requests to any subdomain:

    DocumentRoot /www/subdomain
    ServerName www.domain.tld
    ServerAlias *.domain.tld

Then you can use mod_rewrite to redirect traffic on one of these subdomains to a subfolder or a query string. Something like this:

RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-]+) [NC]
RewriteRule (.*) %2/$1 [L]
share|improve this answer
You can actually avoid the mod_rewrite and do it all in a single VirtualHost block, by using VirtualDocumentRoot. This is called 'Mass Virtual Hosting'. See This allows you to simply create a new website by making a directory. For example if you use the wildcard subdomain in DNS, you can set 'VirtualDocumentRoot /var/www/%-3'. Then, if you simply make a directory /var/www/mysite it will be visible as website mysite.domain.tld. Easy isn't it? The %-3 means, split the hostname and take the third part from the right, i.e. 'mysite'. – Martijn Heemels Jan 6 '10 at 20:59

I dont know about tomcat, but in IIS if the website is set to an IP address (ie no specific host-header/subdomain) all subdomains will point to same site (not sure of the exact terminology here)

If this is the case you can programatically detect the subdomain and react accordingly.

share|improve this answer

One exemplary way to do this is subdomain_fu, which is a subdomain-handler for rails, explained in this screencast:

Conceptually: You can set up apache with a subdomain catch-all server alias and then do the subdomain processing withing your webframework.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.