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 and is also called web root folder or document root directory. For addon domains, the root folder is selected when creating the addon domain in your hosting account.

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. To display hidden files on your account, follow the steps here. If there is still no .htaccess file in the public_html or addon domain’s folder you can easily create one using cPanel.

Then you need to edit the .htaccess file

root folder

 

cPanel Hosting from WebhostFace

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 knowledge base article useful to you