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} ^$ [NC,OR]
RewriteCond %{HTTP_HOST} ^$ 
RewriteCond %{REQUEST_URI} !folder/
RewriteRule (.*) /folder/$1 [L]

Replace ‘‘ 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 A

Senior System Developer at Zeta. Linux lover. Traveller. Let's connect! Whether you're a seasoned DevOps pro or just starting your journey, I'm always eager to engage with like-minded individuals. Follow my blog for regular updates, connect on social media, and let's embark on this DevOps adventure together! Happy coding and deploying!

One thought on “How to change document root of a website using .htaccess

  1. It did not work

    I am using my local development environment to test my application.

    Suppose I have a website on:


    Now in the public folder I have an HTAccess file.

    If I put a “/” inside an href, I want it to go to index.html not the actual Document root,

    Why am I finding it so difficult?

Leave a Reply

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