What's the proper way to setup a client chosen domain name?

view full story

http://serverfault.com – In my web app, I'm toying with the idea of giving my user the opportunity to select a subdomain of their choosing, so they could select something like: foobar.myapp.com where foobar is their chosen subdomain. What is the proper way to go about setting up something like this? .htaccess? Have some api for writing virtual hosts? The application would still always map to one directory on my sever, I just want to give theme a custom URL. (HowTos)