Global Header
4 Mins Read

Steps To Host Primary Domain From A Subfolder htaccess

Home Blog COVID-19 Resources Steps To Host Primary Domain From A Subfolder htaccess
Host Primary Domain
Every domain hosted on a web server will have a public_html directory which will contain all files used for the website. The other Addon domains, on the other hand, use subdirectories, which are present as sub-folders within the public_html directory. A user can use the .htaccess file in the public_html folder to set up their main domain by using a subdirectory on the hosting account. By doing so, the server understands that any request for your main domain has to be redirected to a subdirectory on public_html. These steps are applicable not only for Bluehost servers but also for any web servers in general. Lets understand this concept in slightly more detail.

What is Primary Domain? 

The primary domain is the first domain you purchased at the time of getting the server. In simpler terms, whenever you buy a hosting server, the domain you buy along with the server is known as the primary domain. All the key settings & control for the server will be listed under this domain. These settings will also be applicable to all the other domains which this server will host.

What is a .htaccess file?

Htaccess file is a configuration file in a hosting server that has settings or controls on how a user will be able to access the website. Htaccess file is present at the highest level directory of a server and has information about access control, redirection or shortening of URLs etc. 

Steps to Find the .htaccess file in the File Manager

The first thing is to access the .htaccess file located in your public_html folder. Since this file isn’t visible as a default setting, kindly follow the steps mentioned here to locate & open the .htaccess file:
  1. User must login to their Bluehost.in cPanel account.
  2. Go to the “Files” section and Click the “File Manager” icon.
  3. Under the “View Hidden Files” checkbox, kindly select to view the files.
  4. You are working with your primary domain, so select the WebRoot (public_html/www) option.
  5. Once .htaccess file is found, right click on it & open with Code Editor option.
The above steps can be used to find the hidden htaccess files & update them.

Steps to Edit the Subfolder htaccess to host Primary Domain

The code mentioned below will have to be used in the .htaccess file in the public_html folder of the web server account. Modifications or updates in the code (highlighted by #) will need to be done after inserting the code in the file. # Bluehost.in # .htaccess main domain to subdirectory redirect # Do not change this line. RewriteEngine on # Change example.com to be your main domain. RewriteCond %{HTTP_HOST} ^(www.)?example.com$ # Change ‘subdirectory’ to be the directory you will use for your main domain. RewriteCond %{REQUEST_URI} !^/subdirectory/ # Don’t change the following two lines. RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d # Change ‘subdirectory’ to be the directory you will use for your main domain. RewriteRule ^(.*)$ /subdirectory/$1 # Change example.com to be your main domain again. # Change ‘subdirectory’ to be the directory 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.)?example.com$ RewriteRule ^(/)?$ subdirectory/index.html [L] NOTE: You will need to update “example.com” to your domain at 2 places in the code, and the 3 places of “subdirectory” to the folder where you want your website. The users who visit the website would not be able to differentiate whether the main domain is using a subdirectory or not. The users will view the http://www.example.com/page.html as the website URL address. One thing to iterate here is that these steps won’t work with some website software. In that case, a user will also have to edit & update the $base_url, $live_site or other configuration settings to complete the steps.

Steps for Joomla, Drupal and WordPress Users

For users who are on Joomla, Drupal or WordPress, these steps are not endorsed. It is infact better to use the official documentation & use those steps for hosting the primary domain from a subfolder htaccess. The detailed links based on the CMS being used are: 
  1. Drupal installed in subdirectory but made to appear in root
  2. Joomla – Moving the site among directories/sub-directories
  3. Giving WordPress Its Own Directory
In Conclusion, It is possible for a user to use the .htaccess file in the public_html folder and set up their main domain by using a subdirectory on the web-server account. However, a user must take action depending upon the CMS they are using as all instructions might not be valid in every scenario.
View All

Write A Comment

Your email address will not be published. Required fields are marked *

Longest running WordPress.org recommended host.

Get Up to 61% off on hosting for WordPress Websites and Stores.

Table of Contents