How to Redirect Primary Domain to a Specific Folder in cPanel.

By | December 29, 2019

Whenever we are creating a cPanel Account in WHM, We need to use a Primary Domain for it. That Primary Domain by default points to /public_html and It can not be changed to any other Folder in cPanel. For Other Domain or Subdomain you can change the Document root.

Example: Suppose you have Created cPanel account using a primary domain say “” which by default points to /public_html. Any Web files created under /public_html will be rendered and served as Application Website.

Suppose you have added Subdomain say ““, Which can be pointed to another folder, say /public_html/website1. Likewise you can do for unlimited number of websites by simply changing the document root. In this case if you have 10 Websites then Directory Structure would be like,

/public_html                             => Pointing to primary domain
/public_html/website1           =>  Pointing to Web 1

/publci_html/website2           => Pointing to Web 2  

And Likewise. In this case all website content of domain “” will go to /public_html which actually makes /public_html quite messy. So in order to change the Document root of primary Domain we have to Actually Redirect the traffic to Specific Folder.

Let’s See how we Can do It.

Search for Primary Domain and Click on it.

So here, what we can see is, request coming to will be send to the /public_html. In this case we have to keep all our application data in public_html, but it will be messy as we discussed above. For our case we have created a folder under public_html with a name demodevopsage and copied all website related date to it. Directory structure looks like /public_html/demodevopsage/

In Short we have to redirect the the request coming to /public_html to /public_html/demodevopsage. It’s the best way to organise if you have multiple applications or websites to host.

Go to File Manager ==> Settings (at top right corner) ==> Show Hidden files.

In /Public_html Create a hidden file called .htaccess and paste the below redirect rule.

 RewriteEngine on
 RewriteCond %{HTTP_HOST} ^(www.)?$
 RewriteCond %{REQUEST_URI} !^/demodevopsage/
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^(.*)$ /demodevopsage/$1
 RewriteCond %{HTTP_HOST} ^(www.)?$
 RewriteRule ^(/)?$ demodevopsage/index.html [L] 

Save and Close the page. After doing this, all traffic coming from will go to /public_html and based on the redirect rule we have written in .htacces file, It will be redirected to demodevops folder and Website Content will be Served.

If you Like Our Content here at Devopsage, then please support us by sharing this post.

Please Like and follow us at, LinkedInFacebookTwitter, and GitHub

Also, Please comment on the post with your views and let us know if any changes need to be done.

How to Install WordPress on Top of LAMP Stack on Ubuntu and Redhat/CentOS7 Server.

How to Install and Setup WHM and cPanel On CentOS7 – Part 1

Basic WHM Configuration and Hosting a Website in cPanel Account – Part 2

How to Create Email and FTP Account in cPanel – Part3

Issue – cPanel Email Going to Spam.

Unable to Login cPanel FTP with Failed to Retrieve Directory Listing Error

How to Migrate WordPress Website to cPanel – Part 4

How to Migrate Email Accounts from One cPanel to Another – Part 5

How to use an SSL Certificate for your cPanel Website for Free – Part 6

Redirect HTTP to HTTPS for your Website on cPanel – Part 7

How to Upgrade and Downgrade MariaDB Version in WHM/cPanel – Part 8

cPanel – phpMyAdmin asking for Username and Password. Error – Access Denied.

Leave a Reply

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