I am looking to allow users to control of subdomain of an app I am toying with, much like Basecamp where it is customusername.seework.com
.
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 anything.ourdomain.com 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.
Servername www.ourdomain.com
ServerAlias *.ourdomain.com
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 user.ourdomain.com/foo/bar to www.ourdomain.com/foo/bar?user=user or whatever you prefer.