How To Make Subdomain User Accounts In A Webapp

- 1 answer

I am looking to allow users to control of subdomain of an app I am toying with, much like Basecamp where it is

What is required on the DNS end to allow these to be created dynamically and be available instantly.

And how do you recommend dealing with this in the logic of the site? Htaccess rule to lookup the subdomain in the DB?



The way we do this is to have a 'catch all' for our domain name registered in DNS so that will point to our server.

With Apache you can set up a similar catch-all for your vhosts. The ServerName must be a single static name but the ServerAlias directive can contain a pattern.

ServerAlias *

Now all of the domains will trigger the vhost for our project. The final part is to decode the domain name actually used so that you can work out the username in your code, something like (PHP):

list( $username ) = explode( ".", $_SERVER[ "HTTP_HOST" ] );

or a RewriteRule as already suggested that silently maps to or whatever you prefer.