Knowledge Base

How to change document root folder to some sub-folder using an .htaccess file

By default the web-contents will be loaded from public_html directory of your domain. If you want to load web contents from any specific sub-folder you can implement this by adding the following lines to the .htaccess file in the public_html folder:

RewriteEngine on

RewriteCond %{HTTP_HOST} ^domain-name.com$ [NC,OR]

RewriteCond %{HTTP_HOST} ^www.domain-name.com$

RewriteCond %{REQUEST_URI} !folder-name/

RewriteRule (.*) /folder-name/$1 [L]

You need to replace the following 2 parameters in above code:

Write your main domain name instead of domain-name.com parameter.

Write sub-folder name instead of folder-name parameter.

Note: This will work for Apache web server.

Please rate this article to help us improve our Knowledge Base.

18756 163