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

Last modified: April 13, 2020
You are here:
Estimated reading time: 1 min

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 and is also called web root folder or document root directory.

If your website is located in a sub-folder of the document root and you want it to be displayed when you type your domain name, 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. Or you can create one.

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

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

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

yourdomain.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.

Was this article helpful?
Dislike 0
Views: 18