Hosting Guide

How to change my document root to a folder using .htaccess

On your Ecenica web hosting your web files are served from your public_html directory. This is the default web root or document root for your account.

If you would like to host your website files in a sub-directory and do not want to see the directory in the URL you can use the code below:

  1. Edit your .htaccess in your public_html folder.
  2. Enter the following code at the top of your .htaccess file, replacing example.com and directory with your details.
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^example.com$ [NC,OR]
    RewriteCond %{HTTP_HOST} ^www.example.com$
    RewriteCond %{REQUEST_URI} !directory/
    RewriteRule (.*) /directory/$1 [L]
    
  3. Save

When you visit your domain your website files will be served from your sub-directory.

Was this guide helpful?

Need help with this?

Open a ticket and link to this guide so our team can see what you have tried.

View support tickets

Power your business with Ecenica Hosting

Built for WordPress and serious websites. Fast, secure and supported by real people in the UK.

Ecenica hosting services represented by a connected red route across London