How to change document root using .htaccess

  • Post last modified:December 19, 2019
  • Post category:Apache
  • Post comments:0 Comments
  • Reading time:1 mins read

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