Andrei Stalbe
Andrei Stalbe

Reputation: 1531

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?

Upvotes: 4

Views: 10986

Answers (4)

Pka
Pka

Reputation: 209

How to Create Dynamic Subdomain with the help of PHP and Htaccess We can create dynamic sub domain like top websites who provides us sub domain access with the help of username, I will try to give the best solution for the programmers. I am going to explain how to use htaccess with PHP to create dynamic sub domains, using this you can easily host multiple sub domains on single server.

Process to create dynamic subdomain

  1. Add zone record in domain name setting Open the setting of your Domain name provider and go to your domain DNS(Domain Name Settings), click add zone record.

  2. Create A record and Point to IP Now you need to create a custom A record for all your subdomains.

Select A record, HOST * POINTS TO: Your IP Address

Example : 102.30.138.121

Create a record and point to ip prashantabhishek.com

  1. Repeat the same for host @. Create dynamic subdomain by Prashantabhishek.com

  2. Add CNAME record HOST www points to @ (this refers towards your IP address. )

dynamic sub domain c name record

Save the setting and enjoy the code effect. Read more at : https://www.prashantabhishek.com/blog/view-post/how-to-create-dynamic-subdomain-with-the-help-of-php-and-htaccess/

Upvotes: 0

Karthikeyan Ganesan
Karthikeyan Ganesan

Reputation: 2035

It's easy to create the wildcard subdomains. Check my post for create the wildcard subdomains dynamically in Create subdomains on the fly with .htaccess (PHP) .

Upvotes: 0

Whisperity
Whisperity

Reputation: 3042

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".

Upvotes: 3

Pradeeshnarayan
Pradeeshnarayan

Reputation: 1235

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.

Upvotes: 2

Related Questions