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} ^your-domain-name.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.your-domain-name.com$
RewriteCond %{REQUEST_URI} !new-folder/
RewriteRule (.*) /new-folder/$1 [L]

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

Regards,
Kailash

Leave a Reply