Setting Up Customer-Specific Domains

I can go to Fog Creek's web site, setup a new account, and they will instantly assign me a URL such as 'mycompany.fogbugz.com' (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 'mycompany.fogbugz.com' set up in DNS in some special way other than how one would setup a vanilla 'www.foo.com' 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!


Solution 1:

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    1.2.3.4

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

<VirtualHost 111.22.33.55>
    DocumentRoot /www/subdomain
    ServerName www.domain.tld
    ServerAlias *.domain.tld
</VirtualHost>

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-]+).domain.com [NC]
RewriteRule (.*) %2/$1 [L]

Solution 2:

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.