Article

Pointing a Root Domain to a Subfolder Using .htaccess

Website & Hosting
Created 2026-07-31 16:14:06
Updated 2026-07-31 16:14:06
Views 91

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

  1. Log in to cPanel.
  2. Open File Manager.
  3. Navigate to the public_html directory.
  4. Enable Show Hidden Files from the File Manager settings so that .htaccess files 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 .htaccess file must be placed directly inside public_html.
  • The subfolder should contain the website’s index.php or index.html file.
  • 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_rewrite is enabled. This is enabled by default on most cPanel hosting platforms.
  • Existing .htaccess rules, such as WordPress or Laravel rules, may need to be placed inside the subfolder’s own .htaccess file.
  • Back up the existing .htaccess file 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.