How to change document root using .htaccess

Change document root using .htaccess

If you have cPanel control panel or other control panel, your website’s document root is fixed by default.

However there may be a case where you need to change the defualt document for your website. This is possible via .htaccess. You will need to add the following code in your .htaccess file:

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

Replace with your actual web site name and new-folder with your new destination folder.


Leave a Reply