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
Open the setting of your Domain name provider and go to your domain DNS(Domain Name Settings), click add zone record.
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 : :
See animation to understand
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 |
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.
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
Prashant Kr Abhishek
Software Engineer
Stay in the Know, Signup for emails to get new updates around the world !
© 2024 Prashantabhishek.com | All rights reserved