Casbay Knowledge Base

Search our articles or browse by category below

HOW TO: Change the root directory of Primary domain with .htaccess

Last modified: October 1, 2022
Estimated reading time: 1 min

HOW TO: Change the root directory of Primary domain with .htaccess

If you have a website installed for the primary domain of your hosting account. By default your website is loaded from the public_html folder. Public_html is the root folder for the primary domain. Besides that, we also call it web root folder or document root directory.

If your website is located in a sub-folder of the document root and you want to display it when typing your domain name, here is what you should do. Firstly, you need to edit the .htaccess file in your public_html folder. If you cannot find the .htaccess, it is possible that the file is hidden. Then you can create one.

1) Adding rules

In the .htaccess file, you need to add the following rules to redirect the root folder:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^enteryourdomain.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.enteryourdomain.com$
RewriteCond %{REQUEST_URI} !folder/
RewriteRule (.*) /folder/$1 [L]

2) Replacing the lines

You should replace the following 2 strings in the lines above:

enteryourdomain.com – Type the domain name in question.
folder – Type the name of the sub-folder which the website is located in.

After you have added the code and saved the .htaccess file, open your domain name in a browser and you should see the website which is in the sub-folder.

Read our next article- HOW TO: Change SSH Port

Was this article helpful?
Dislike 0
Previous: Overview of the Vim Text Editor
Next: TIPS: IIS 6.0 – Security Best Practices