HostOnNet Blog

How to change my document root folder using an .htaccess file?

Looking for Linux Server Admin or WordPress Expert? We can help.

By default website is loaded from the public_html folder of hosting account. The public_html directory is also called document root folder.

If you’ve created a test website under a sub-folder and you want it to be displayed when you type your domain name, add the following lines to the .htaccess file in the public_html folder:

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

In the above lines you should replace the following 2 strings:

domain-name.com – Type your own domain name
folder – Type the name of the sub-folder which has the demo/test website

Incase there is no .htaccess file you may create a new .htaccess file using filemanager in cpanel.

About Annie

I've been working in Technical Section for over 10 years in a wide range of tech jobs from Tech Support to Software Testing. I started writing blog for my future reference and useful for all.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.