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.

Author

5 Comments

  1. What’s up too every body, it’s my first visit of this web site; his web site carres awesome and
    truly fine data for visitors.

  2. I have been browsing online more than three hours as of late, but
    I never discovered any attention-grabbing article like yours.
    It’s beautiful price sufficient for me. Personally, if all web owners and bloggers made
    just right content as you probably did, the internet
    can be a lot more helpful than ever before.

  3. Hello there! This post couldn’t be written any better!
    Reading this post reminds me of my good old room mate!
    He always kept talking about this. I will forward this page to him.

    Pretty sure he will have a good read. Thanks for sharing!

  4. An outstanding share! I’ve just forwarded this onto a
    coworker who was conducting a little research on this.
    And he in fact bought me dinner because I stumbled upon it
    for him… lol. So allow me to reword this…. Thanks for the meal!!

    But yeah, thanx for spending some time to discuss
    this issue here on your web page.

Write A Comment