Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create dynamic subdomains

It has been a while since I've been thinking over this feature that some websites are implementing and it looks to be very successful.

Websites like tumblr.com, blogger.com, wordpress.com allow users to register new sub-domain names from within the website by using a simple HTML/PHP form. With my current knowledge of PHP I couldn't figure out myself how this is done. I've read some posts on this and still can't build a clear idea about this.

So, how do I create a script that allows users to register their own sub-domains on my website (www.username.mydomain.com) and more than that, how do I allow them to use a different website template (as wordpress.com does). Is this possible to be done on a shared server or a dedicated server is needed?

like image 632
Andrei Stalbe Avatar asked Sep 12 '25 09:09

Andrei Stalbe


2 Answers

These subdomain issues are brought down to the level of nice URLs, friendly URLs etcetera, as this feature has various names.

Basically what you do is that you set up a redirection so that if someone enters foobar.example.org, the server will serve example.org/user.php?name=foobar or example.org/foobar. After this, it's only a matter of how you put together your PHP script so that user.php or the contents of /foobar is parsed properly. The "registration" part is statically done in the .htaccess file in your DocumentRoot.

Of course this will need some sort of proper error handling for a nonexistant "subdomain".

like image 189
Whisperity Avatar answered Sep 14 '25 01:09

Whisperity


I can tell you a simple approach. First you have to enable subdomains in your domain. You can search for 'wildcard-dns and sub domains'. Next all is programming logic.

While registering you can ask for a unique subdomain name. After login, redirect it to the registered subdomain.

like image 42
Pradeeshnarayan Avatar answered Sep 14 '25 01:09

Pradeeshnarayan