How To Host The Main Domain Pointing To Subfolder?

It’s been awkward to keep all the main domain files maintaining under public_html directory. So here is a solution to organize your main/primary domain pointing to a subfolder.

Simply Follow These Steps To Host Primary Domain Point To Subfolder:

Step 1: Log into your web host service provider and go to “FILES” section.

Files Manager

Files Manager

Step 2: Create a subfolder for your ‘primary domain’ under public_html directory. For Example: ‘first’, this could be your main/primary domain name of the website.

File Manager htaccess

File Manager htaccess

Step 3:Now Edit your .htaccess file under the public_html directory from the web host File Manager Directory Section. This file will be stored as hidden, so you need to select the option ‘Show Hidden Files’ from the File Manager.

File Manager Directory Selection

File Manager Directory Selection

Step 4: Right click the .htaccess file and choose as “Code Editor”

Step 5: Add the following code to your .htaccess file in the public_html folder of your hosting account.

Please note: You will need to insert the following code and make modifications as noted in the (#) comments.


# .htaccess main domain to subdirectory redirect

# Do not change this line.
RewriteEngine on

# Change to be your main domain.
RewriteCond %{HTTP_HOST} ^(www.)?$

# Change ‘subfolder’ to be the folder you will use for your main domain.
RewriteCond %{REQUEST_URI} !^/subfolder/

# Don’t change this line.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Change ‘subfolder’ to be the folder you will use for your main/primary domain.
RewriteRule ^(.*)$ /subfolder/$1

# Change to be your main domain again.
# Change ‘subfolder’ to be the folder you will use for your main domain
# followed by / then the main file for your site, index.php, index.html, etc.

RewriteCond %{HTTP_HOST} ^(www.)?$
RewriteRule ^(/)?$ subfolder/index.php [L]


Now visitors to your Website will not be able to tell that your main/primary domain is using a subdirectory in your web hosting.