Changing the Document Root via .htaccess

Step 1: Access Your cPanel File Manager

  1. Log in to your web hosting account and navigate to the cPanel dashboard.
  2. Locate the “Files” section and click on the “File Manager” option.
  3. Ensure that you are in the “public_html” directory, which is the default document root for the main domain in cPanel.

Step 2: Create or Edit the .htaccess File

  1. Check if there is an existing .htaccess file in the “public_html” directory. If there is, proceed to step 3.
  2. If there is no .htaccess file, create one by clicking on the “Create” or “New File” button in the File Manager toolbar. Name the file “.htaccess” (including the period at the beginning) and save it in the “public_html” directory.

Step 3: Edit the .htaccess File to Change the Document Root

  1. Open the .htaccess file in the cPanel File Manager by right-clicking on it and selecting “Edit” or “Code Edit.”
  2. Add the following code to the .htaccess file:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.tld$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.domain.tld$
RewriteCond %{REQUEST_URI} !new-document-root/
RewriteRule (.*) /new-document-root/$1 [L]
Scroll to Top