How To Make Subdomain User Accounts In A Webapp
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
?
Answer
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.
Related Questions
- → Analysis of Flux implementations
- → Use Buttons as a Switch or Checkbox
- → React + Parse or React + Meteor?
- → Dynamic meta tag binding using REST api SEO impact
- → Do I need a client side framework? (web app)
- → Use react js with existing java web application
- → Is it better to Embed a CSV file or Connect to MongoDB in webapp?
- → What is the benefits of Creating menu for web application based on database?
- → Making android apps using a locally hosted webserver
- → indexedDB.open() takes around 10sec on iOS Safari
- → How to make subdomain user accounts in a webapp
- → A large query on the parent component or a series of small queries on each children?
- → Securely storing auth token in React Frontend