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

By default your 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'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_htmlfolder:

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 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 test folder

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Leverage Browser Caching for Images, CSS and JS

To leverage your browser's caching generally means that you can specify how long browsers should...

Enable gZIP via .htaccess

To enable gZIP for your text, html, JavaScript, CSS and XML add these files to your .htaccess:...

Last-modified Header Explained

The last-modified header is an HTTP header that tells your browser when was the last time the...

How to enable Mod_Gzip

Mod_Gzip is an external extension module for Apache 1.3 web servers implemented to help with size...

How to change the default umask for Apache/Php

Apache/Php umask determines the permissions for the newly created files. On a VPS / Dedicated...