Just Host Web Hosting Help

How to host the Primary Domain from a subfolder (.htaccess)

Summary

The public_html directory for all of its Web site files. Addon domains use sub directories inside the public_html directory. In order to also set up your main domain to use a subdirectory 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 main domain will be redirected to a subdirectory on public_html.

Locating the .htaccess file in the File Manager

  1. Log in to the Just Host cPanel.
  2. Scroll down to the Files section.
  3. Click the File Manager icon.
  4. Check the View Hidden Files checkbox.
  5. You are working with your primary domain, so select the WebRoot (public_html/www) option.
  6. Right click the .htaccess and choose Code Editor

Modifying the .htaccess

You will want to insert the following code block and make modifications as noted in the (#) comments. You will need to change the two instances of example.com to your domain, and the three instances of subdirectory to the folder where you want your site.

# Justhost.com
        # .htaccess main domain to subdirectory redirect
        # Copy and paste the following code into the .htaccess file
        # in the public_html folder of your hosting account
        # make the changes to the file according to the instructions.
        # 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 these line.
        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 Web site will not be able to tell that your main domain is using a subdirectory, they will still see the Web site address as http://www.example.com/page.html.

Note: This will not work with some website software. You will also need to modify the $base_url, $live_site or other configuration settings in those to finish the process.

When using WordPress

When you are using WordPress it is recommended that you follow their instructions found in the WordPress codex, Giving WordPress Its Own Directory

Knowledgebase Article 220,793 views bookmark tags: domain htaccess (updated 398 days ago)


Was this resource helpful?

Did this resolve your issue?


Please add any other comments or suggestions about this content:





Recommended Help Content

I do not want to see addon.maindomain.com. How do I do that? (updated 389 days ago)

How do I stop people from being able to use the addon domain as a subdomain of the primary domain? (updated 398 days ago)
Knowledgebase Article 84,642 views tags: addon domain htaccess

How to Stop A Directory Index From Being Shown (updated 459 days ago)
Knowledgebase Article 57,286 views tags: directory htaccess index

Related Help Content

What is the absolute path to my site? (updated 1051 days ago)
Knowledgebase Article 60,696 views tags: cgi directory folder path perl

How do I assign a domain so it does not point to my primary domain? (updated 91 days ago)
Knowledgebase Article 153,643 views tags: domain

What is the .htaccess file and where can I find more information? (updated 128 days ago)
Knowledgebase Article 420,725 views tags: htaccess tips tricks

What steps are necessary if I decide to transfer a domain to another registrar? (updated 287 days ago)
Knowledgebase Article 85,020 views tags: company domain epp host registrar site steps transfer website

I am having problems seeing the changes I made in Rapid Weaver, whats wrong I know they were published to the correct directory? Usually the public_html for main domains. (updated 1416 days ago)
Knowledgebase Article 36,499 views tags:

How to use a WildCard SSL Certificate (updated 251 days ago)
Knowledgebase Article 21,120 views tags: htaccess reseller ssl subdomain subfolder wildcard

An expanded explanation of what the main mail sub folders are, such as cur, new and tmp. (updated 205 days ago)
Knowledgebase Article 2,127 views tags: directory email webmail

Can I have multiple domains pointing to my site or to a directory on my site? (updated 399 days ago)
Knowledgebase Article 81,484 views tags: domain domains