How to 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

Posted in Apache.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.