How can I host my primary domain from a sub-folder (.htaccess) Print

  • 51

By default your primary domain will use the public_html directory for it's website files. Additional domains ( add-on, sub-domains) will use sub-directories inside the public_html folder.

It is possible to host your primary domain from a sub-folder within the public_html by setting up a redirect in the .htaccess file inside your public_html folder so the server redirects all requests for your primary domain to the to the sub folder inside public_html.

Your website visitors will not be able to tell that your primary domain is loading from a sub-folder, they will still see your website address as http://www.domain.com/site.html

Modifying the .htaccess file

Add the following lines to the .htaccess file in the public_html folder and make modifications as noted in the (#) comments.

# .htaccess main domain to subfolder redirect
# Do not edit this line
RewriteEngine on

# Replace primarydomain.com with your primary domain.
RewriteCond %{HTTP_HOST} ^(www.)?primarydomain.com$

# Replace 'subfolder' with sub-folder you will be using for your primary domain.
RewriteCond %{REQUEST_URI} !^/subfolder/

# Do not edit this line
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Replace 'subfolder' to be the folder you will use for your primary domain.
RewriteRule ^(.*)$ /subfolder/$1

# Replace primarydomain.com with your primary domain again.
# Replace 'subfolder' with the sub folder you want to use for your primary domain
# followed by / then the main file for your site, index.php, index.html, etc.

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


Was this answer helpful?

« Back

Powered by WHMCompleteSolution