4

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?

Whisperity
  • 3,012
  • 1
  • 19
  • 36
Andrei Stalbe
  • 1,511
  • 6
  • 26
  • 44
  • Check my post for create the wildcard subdomains dynamically in https://stackoverflow.com/questions/586129/create-subdomains-on-the-fly-with-htaccess-php . – Karthikeyan Ganesan Jun 07 '17 at 08:11

4 Answers4

3

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

Community
  • 1
  • 1
Whisperity
  • 3,012
  • 1
  • 19
  • 36
  • Yes, I've read some posts about redirection and it looks to be a good alternative. But, the thing is, as I imagine, the URL in the address bar changes after redirection, from `user.mydomain.com` to `mydomain.com/user`. How do I do to keep the URL unchanged like `user.mydomain.com/page1`, `user.mydomain.com/page2`etc. And, one more question, is this can be done on a shared server, because some hosting companies doesn't allow users to have access to the `.htaccess` and change it. – Andrei Stalbe Aug 07 '12 at 07:48
  • Advanced configurations like these might not be pulled off on a shared server as it requires extensive usage of `.htaccess`. Companies like Wordpress and Tumblr have their own dedicated server clusters. The related `.htaccess` directive is the [`mod_rewrite`](http://httpd.apache.org/docs/current/mod/mod_rewrite.html) module. – Whisperity Aug 07 '12 at 08:43
2

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.

Pradeeshnarayan
  • 1,235
  • 10
  • 21
0

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

Karthikeyan Ganesan
  • 1,901
  • 20
  • 23
0

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/

Pka
  • 209
  • 2
  • 2