Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

3 Answers 3

Yes, it can be done through .htaccess but it will only work if you have a wildcard DNS entry for the domain or you also add a DNS record for each sub-domain.

share|improve this answer
add comment

I would set up an API that writes virtual hosts as you suggest, just make sure it makes the appropriate checks to make sure nothing dodgy happens; such as multiple VH with the same name, naming conventions etc...

share|improve this answer
add comment

i think the mod_rewrite way is more intended to serve different directories, so i'd rather handle it inside the application itself. After all you're talking just about URL rewriting within the same application. A wild card DNS record would still be needed, tho.

I wouldn't even bother with a vhost api.

Either way, mind of course that using HTTP HOST header to select the content served has security implications, like any other user provided input.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.