This guide explains how to make a root domain load a website stored inside a subfolder of public_html, without displaying the subfolder in the browser address bar.
Example folder structure
public_html/
├── .htaccess
└── website/
├── index.php
├── css/
├── images/
└── other website files
In this example, visiting:
https://example.com
will internally load the website from:
public_html/website/
The browser will continue to display https://example.com rather than https://example.com/website.
Step 1: Open cPanel File Manager
- Log in to cPanel.
- Open File Manager.
- Navigate to the
public_htmldirectory. - Enable Show Hidden Files from the File Manager settings so that
.htaccessfiles are visible.
Step 2: Create or edit the .htaccess file
Inside public_html, create or edit the file named:
.htaccess
Add the following rules:
RewriteEngine On
# Do not rewrite requests that already point to the subfolder
RewriteCond %{REQUEST_URI} !^/website/
# Internally load all requests from the subfolder
RewriteRule ^(.*)$ website/$1 [L]
Replace website with the actual name of the supplied subfolder.
For example, if the website files are located in:
public_html/customer-site/
use:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/customer-site/
RewriteRule ^(.*)$ customer-site/$1 [L]
Recommended version
The following version also prevents existing files or folders in the root public_html directory from being rewritten:
RewriteEngine On
# Do not rewrite existing files or directories
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Prevent a rewrite loop
RewriteCond %{REQUEST_URI} !^/website/
# Internally serve the website from the subfolder
RewriteRule ^(.*)$ website/$1 [L]
Replace website with the correct subfolder name.
Important notes
- The
.htaccessfile must be placed directly insidepublic_html. - The subfolder should contain the website’s
index.phporindex.htmlfile. - Do not include a leading slash before the subfolder name in the
RewriteRule. - This is an internal rewrite, not a browser redirect, so the subfolder remains hidden from the URL.
- Ensure Apache
mod_rewriteis enabled. This is enabled by default on most cPanel hosting platforms. - Existing
.htaccessrules, such as WordPress or Laravel rules, may need to be placed inside the subfolder’s own.htaccessfile. - Back up the existing
.htaccessfile before making changes.
Testing
After saving the file, visit the root domain:
https://example.com
The website stored in the supplied subfolder should now load while the browser continues to show the root domain.