The magical and easiest solution to place a subdomain before or after the primary domain is in the .htaccess file. We are basing this tutorial in Apache, but this method differs very little or not at other platforms.
First you need to decide where you want to place a subdomain, before or after the primary domain. I personally prefer to put it back, but it depends on the situation and the plan.
To set, display subdomain after primary domain.
This can be called differently as a subfolder.
Just create a folder in the root of your primary domain. Let’s say, you have a domain “example” with extension “.com” and you want to create a subdomanin named e.g “subdomain” it will look like this: example.com/subdomain .
So, to use this method there is no need to to set any record such as cname in you domain settings. Also, it is not necessary to place any extra code in .htaccess, just remember to name the folder “subdomain” or whatever name you want to appear after the domain.
To set, display subdomain before primary domain.
Let’s say, you have a domain “example” with extension “.com” and you want to create a subdomanin named “subdomain“.
Create a folder named “subdomain” in the root of your primary domain. The full domain should look like: subdomain.example.com.
After you create a folder named “subdomain” or any other name of your choice you should:
- Go to your domain registrar and add a cname “subdomain” then point that to your primary domain e.g example.com. Methods for adding new record varies depending on the domain registrar, but all have a nearly similar setup.
- In cPanel click Subdomain, select your primary domain then in Document Root enter public_html/subdomain or any other name of the folder you created for subdomain.
- In .htaccess file enter only a simple code: RewriteEngine On if that file is empty. If you plan to install WordPress or any other CMS then you don’t need to create or edit .htaccess file.