Mapping subdomain before or after the primary domain

subdomain, subdir

The magical and easiest solution to place a subdomain before or after the primary domain is in the .htaccess file.

First you need to decide where you want to place a subdomain, before or after the primary domain. I personally prefer to put it after primary domain (subfolder), however it depends on the planning of the website structure.

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.com” and you want to create a subdomanin named e.g “subdomain” it will look like this: example.com/subdomain .

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:

  1. 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.
  2. 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.
  3. 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.

Related posts