4

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!

migrated from stackoverflow.com Jan 4 '10 at 1:47

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

7

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]
  • 1
    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 httpd.apache.org/docs/2.2/vhosts/mass.html. 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
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.

1

One exemplary way to do this is subdomain_fu, which is a subdomain-handler for rails, explained in this screencast: http://media.railscasts.com/videos/123_subdomains.mov.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy