How can I change the document root of my website using .htaccess

By default the document root of your website on a cPanel based server is /home/$username/public_html . At the time anyone search your domain from there own end the site displays the index page from default location. That means from public_html folder. Here I’m explaining the way to change this default folder. That means you can customize the DNS fetching(Index page fetching) from your own folder.
This is possible via .htaccess. You will need to add the following code in your .htaccess file:

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

Replace ‘domain.com’ with your domain name and ‘folder’ with your custom folder name where you kept the index.

Thats it. Try this and reply me.

Arunlal Ashok

Linux Cloud Infrastructure / DevOps Engineer. I'm dealing Linux servers since 2012. I started this blog to share and discuss my ideas.

Always happy for an open discussion! Write to arun (@) crybit (dot) com. Check about me for more details. About this blog and our strong members, check The team CryBit.com

Leave a Reply

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