Knowledge Base
MilesWeb / How-Tos

How To Change Document Root Using .htaccess File ?

Approx. read time : 2 min

Watch this video for a step by step process on how to change document root using .htaccess file?

The time your account is created on a shared/reseller host, by default the website loads from public_html directory. This directory is the Document Root OR the web directory. What if you want the website content to load from some other directory OR a sub directory ?

Simply, add the code below in .htaccess file under the account. You can create the .htaccess file using File Manager from cPanel. It will redirect to the sub directory when your domain is accessed.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.domain.com$
RewriteCond %{REQUEST_URI} !web/
RewriteRule (.*) /web/$1 [L]

Make sure you replace domain.com with your actual domain name & web with your actual sub folder.

With over 10+ years of experience in the web hosting industry, I have achieved extensive exposure to result-oriented methodologies. And expertise in different domains like Datacentre Services, Cloud computing technology, Web hosting industry and many more.
Need help? We’re always here for you.