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

By default your main website is loaded from the public_html folder of your account. The public_html directory is also called web root folder or document root folder. If you would like to keep your site's files in a sub folder of the public_html, and do not want the sub folder to appear as a part of the URL to your website, you can mask the subfolder from the URL by placing the following directives in the .htaccess file inside 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:

domain-name.com - Type your own domain name
folder - Type the name of the subfolder which has the test/development website

If there is no .htaccess file in the public_html folder you can easily create one using cPanel->File Manager. Then, type your domain name in a browser and you should see the website which is in your sub folder.

  • htaccess, linux, document root
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Pages getting 500 error

TVMserver Linux cPanel Hostings uses SuPHP to secure PHP. suPHP is a tool for executing PHP...

Disabling Cache on Linux Server

You can disable caching of files by adding this code to the bottom of .htaccess <Files...

Redirect HTTP to HTTPS automatically in Linux / Cpanel

If you have a secure certificate (SSL) on your website, you can automatically redirect visitors...

Connection is insecure - SSL certificate issue

First you need to check whether SSL certificate is installed in your hosting account.  You can...