Loading...

Knowledge Base
Up to 75% off on hosting for WordPress websites and online stores

How To Host Primary Domain From A Subfolder htaccess

Your primary domain will default use the public_html directory for all its website files. Addon domains use subdirectories inside the public_html directory.

To also host the primary domain from a subfolder on your hosting account, you will need to set up a redirect in the .htaccess file in the public_html folder so that the server knows that any request for your primary domain will be redirected to a subdirectory on public_html.

Host the  Primary Domain from a Subfolder via .htaccess File

Important note: If you are using Joomla, Drupal, or WordPress, it is recommended that you refrain from following these instructions but should follow the instructions provided in the official documentation. Please see the links below for instructions specific to your CMS.

To host the primary domain from a subfolder via .htaccess: 

  1. Log in to your Bluehost Account Manager.
  2. Click the Hosting tab on the left-hand side menu.
    Bluehost account manager hosting tab
  3. Next, click the File Manager button under Quick Links.
    Snapshot of Quick Links, selecting File Manager option
  4. Look for the Settings button towards the upper right corner of your screen.
  5. From here, click the Preferences popup and the checkbox for Show Hidden Files (dotfiles).
    Preferences window with options to show hidden files and set web root directory for 'example.com'
  6. Right-click on the file, then click on Edit from the menu.
    .htaccess file option, selecting Edit
  7. A dialogue box may ask about encoding; click the Edit button to continue. The editor will open in a new window.
  8. Modify the .htaccess file.
    The following code must be added to the .htaccess file in the public_html folder of your hosting account. You must insert the next code block and make modifications as noted in the (#) comments.

    Important note: You must change the two instances of example.com to your domain and the three instances of the subdirectory to the folder where you want your site.

    # %%brandDomain%%
    # .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] 

Visitors to your Website will not be able to tell that your primary domain uses a subdirectory; they will still see the Website address as http://www.example.com/page.html.

Please note that this will not work with some website software. To finish the process, you may also need to modify the $base_url, $live_site, or other configuration settings.

Summary

If you want to host the primary domain from a subfolder on your hosting account, you need to set up a redirect in the .htaccess file, which is located in the public_html folder. You must modify the .htaccess file and add specific code to do this.

However, it is important to note that this method may differ from some website software. If you are using Joomla, Drupal, or WordPress, it is recommended that you follow the instructions provided in the official documentation. By hosting your primary domain from a subfolder, you can keep your website well-organized and make navigating more accessible for visitors.

If you need further assistance, feel free to contact us via Chat or Phone:

  • Chat Support - While on our website, you should see a CHAT bubble in the bottom right-hand corner of the page. Click anywhere on the bubble to begin a chat session.
  • Phone Support -
    • US: 888-401-4678
    • International: +1 801-765-9400

You may also refer to our Knowledge Base articles to help answer common questions and guide you through various setup, configuration, and troubleshooting steps.

Did you find this article helpful?

 
* Your feedback is too short

Loading...