Skip to content

Changing the document root directory

The document root directory is the folder where your website files are stored and served to visitors. By default, on ruachost.com shared hosting accounts, this is the /home/username/public_html directory. You may want to change the document root if you’re testing a new application, staging a site, or reorganizing your file structure.

  • Test a new application without affecting the live site.
  • Stage a website before launch.
  • Organize files into separate directories for different projects.
  • Improve security by isolating public files from private ones.
Section titled “Method 1: Using Symbolic Links (SSH Access Required)”
  1. Log in to your account via SSH.

  2. Move the existing public_html directory:

    Terminal window
    mv ~/public_html ~/public_html_backup

    ⚠️ Important: Run the next command immediately to avoid downtime

  3. Create a symbolic link pointing to the new directory:

    Terminal window
    ln -s ~/new_document_root ~/public_html
  4. Verify the symbolic link:

    Terminal window
    ls -l ~/public_html

    Output should show public_html -> new_document_root.

  5. Test your site in a browser.

???? Note: The server’s cron job will reset permissions every 4 hours (e.g., 4:12, 8:12, 12:12). To minimize downtime, make changes just before one of these times.

If you don’t have SSH access, you can redirect requests to a subfolder via .htaccess.

  1. Log in to cPanel.
  2. Open File Manager and navigate to public_html.
  3. Edit or create the .htaccess file.
  4. Add the following rules (replace example.com and subfolder):
# Redirect main domain to subfolder
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example.com$
RewriteCond %{REQUEST_URI} !^/subfolder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /subfolder/$1
# Load index file from subfolder
RewriteCond %{HTTP_HOST} ^(www\.)?example.com$
RewriteRule ^(/)?$ subfolder/index.html [L]
  • Terminal window
    rm ~/public_html
    mv ~/public_html_backup ~/public_html
  • .htaccess Method: Rename or delete the .htaccess rules that redirect traffic.