How to change document root of a website using .htaccess

[sg_popup id=”2″ event=”onload”][/sg_popup]How to change document root? This will help if you want to change the document root of you website from the default location.

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 or the content from this default location. That means from public_html folder. So How to change document root?

How to migrate all cPanel accounts without its home directory?

Yeah, definitely! You can create a complete cPanel account backup by excluding the home directory. This is very important, because, if the home directory of cPanel accounts have large amount of data, this will increase the total time for the account migration.

Generating backup and restoring it for a large account is much time consuming process. If you need a faster solution, exclude the home directory then complete the account migration with out its home directory. After that start syncing the home directory from source to destination server 🙂

How to change document root

In this blog article, I’m explaining the way to change this default root folder of a hosted website on a cPanel server. cPanel using HTTP as web server. That means you can customise 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.

Affordable cPanel hosting - Easy sign up - 24/7 support
Affordable cPanel hosting – Easy sign up – 24/7 support

Now you can configure your cPanel backup to Google Drive!!

They introduced this feature in its latest version, now onward from version 66. Please make sure that your server has the latest version of cPanel software.

You can check the version by running the following command as root.

Post navigation

Arunlal Ashok

Linux Systems Architect at Endurance International Group. Linux lover. Like to play on Linux console. I started this blog to share and discuss Linux thoughts.

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 *