Home / Tutorials / Create Dynamic Subdomains using PHP and Htaccess
Subdomain and Mandomain

Create Dynamic Subdomains using PHP and Htaccess

Dynamic subdomains like Google Blogger and Tumblr.com, I know the vast majority of the general population are searching for better arrangement. Today I need to disclose how to accomplish this utilizing .htaccess with PHP. I particularly love to compose .htaccess record, utilizing this you can without much of a stretch host various areas in single server. This element subdomain framework is the base for cloud administrations, soon I will accompany new instructional exercise. I trust this post will take care of your issue, please investigate this live demo.

Step 1
Go to your domain DNS(Domain Name Settings), click add zone record.

arecord

Step 2
You need to create a custom A record to serve all your subdomains. Select A record, HOST * POINTS TO: Your ID Address(Eg: 172.23.255.81)

aZone

Step 3
Repeat the same for HOST @, here is the listed A records.
arecord2

Step 4
Now add CNAME record, HOST www POINTS TO @ this refers to your IP address.

czone2

Step 5
CNAME list should be in following way.

cname

Step 6
Save all of your domain DNS settings.

Working with Hosting Server

We can achieve dynamic subdomains system with .htaccess URL redirection configuration file, here I have a project directory called yourwesbite_folder

inside

(1) Root .htaccess
This file is redirection http://www.yourwesbite.com to http://yourwebsite.com for home page use. All of the subdomain redirection to yourwebsite_folder

(2) Inside Folder .htaccess
This file is rewriting the subdomain urls.

http://yourwesbite.com/index.php?siteName=codemorning
to
http://codemorning.yourwebsite.com

More .htaccess tips: Htaccess File Tutorial and Tips.

index.php
This file contains simple PHP code, using regular expressions validating the subdomain value.

No Subdomain Folder

If you are using root directory(htdocs/public_html) as a project directory, use this following .htaccess file.

 

 

About cmadmin

Web Developer & Designer | Android App Developer

Check Also

frameworks-banner

How to make your own PHP framework?

Building your own framework can be useful for the following reasons: You can learn a …

php-framework

What is a PHP framework – Which one is best?

Framework is a tool to help you develop applications faster and better. It is a …

Login


Username
Create an Account!
Password
Forgot Password? (close)

Sign Up


Username
Email
Password
Confirm Password
Want to Login? (close)

Forget Password?


Username or Email
(close)
SHARE
OR
SUBSCRIBE
To get latest new / tutorial / technology / development information subscribe with us.
ARE YOU READY? GET IT NOW!
Lets Get Updated with latest trends & tutorials!
Your Information will never be shared with any third party.
Ready for latest tutorials & tools !
OR SUBSCRIBE WITH