How to Create Dynamic Subdomain with the help of PHP and Htaccess

How to Create Dynamic Subdomain with the help of PHP and Htaccess

We can create dynamic subdomains like top websites who provide us subdomain access with the help of username, I will try to give the best solution. I am going to explain how to use htaccess with PHP to create dynamic subdomains, using this you can easily host multiple subdomains on a single server. 
Download Example

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

https://www.prashantabhishek.com/blog/uploads/domain_name_setting_prashantabhishek.com.png

2. Create A record and Point to IP

Now you have to add an A record to your DNS  zone file for a domain or website  registered along with your Domain Name supplier. An A record connects your domain name to an IP address and lets web browsers find your website. You can use an A record to point to your hosting account or to create a subdomain. If your domain  isn't registered with GoDaddy, you can add an A record using DNS hosting.

Now you wish to form a custom A record for all of your subdomains.

Select A record, HOST * POINTS to Your IP Address 

Example: 102.30.138.121

If you have got GoDaddy account follow these step :  : 

  • Log in to your GoDaddy account and open your product.
  • From the Domain Manager, select your domain name from the list to access the Domain Settings page.
  • Scroll all the way down to the Additional Settings section and choose Manage DNS.
  • On the DNS Management page, at the bottom of the Records section, click Add.
  • Select A from the drop down menu.
  • Complete the desired fields

See animation to understand

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

 Field     name   What to enter
 Host   The host name the A record links to. Type @ to point directly to your domain name.
 Points  to   The IP address you are setting as the destination for the host
 TTL  How long the server should cache information

4. Add CNAME record

 HOST www(web) points  to @ (this refers towards your desired IP address. )

Add a CNAME record to your DNS zone file for a domain registered. CNAME records use a domain prefix, like blog.prashantabhishek.com to point to different domain name or URL. To feature a subdomain that points to an IP address, you'll be able to add a subdomain. If your domain is not registered with GoDaddy,  you'll be able to add a CNAME using DNS hosting.

dynamic sub domain c name record

   Field   name What to enter
  Host The hostname, or prefix, the CNAME record will be set to. 
You can include a period (.) but not as the first or last character. Consecutive periods (...) are not allowed. The host cannot exceed 25 characters or be the @ symbol.
 Points   to The URL you are setting as the destination for the host. Type @ to point directly to your root domain name.
  TTL How long the server should cache information

 

Save the setting and enjoy the code.

Download Example to Create Subdomain

Some image credit: Godaddy

 

Read More

Send SMS using Twilio SDK in PHP - Download Complete Code

Send an Email Using Phpmailer and Amazon SES in PHP with Source Code

How to Create Dynamic Modal Box with Ajax, PHP and Mysql