Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

Change the Document Root Using .htaccess

This guide shows you how to make your domain show a different folder by using a .htaccess file.

How-To Guides2 min read10 steps

What do these words mean?

The document root is the main folder where your website files live. When someone visits your domain, the server looks in this folder first. On many hosting accounts it is called public_html.

A .htaccess file is a small settings file for the Apache web server. It sits in a folder and changes how that folder behaves. The name starts with a dot, which hides the file on many systems.

You cannot truly change the document root from .htaccess. But you can send visitors to a subfolder, which gives the same result for most people.

Example

Your site files are in public_html/mysite. You want visitors to see them when they open example.com.

Warning: A mistake in .htaccess can cause a 500 error and take your site down. Download a copy of the current file before you edit.

Steps

  1. Log in to your hosting control panel.
  2. Open File Manager.
  3. Click Settings and tick Show Hidden Files (dotfiles). Save.
  4. Go to public_html.
  5. Find .htaccess. If it does not exist, click + File and create it.
  6. Right-click it and pick Download to keep a backup.
  7. Right-click it again and choose Edit.
  8. Add these lines, changing example.com and mysite to your own names.
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
    RewriteCond %{REQUEST_URI} !^/mysite/
    RewriteRule ^(.*)$ /mysite/$1 [L]
  9. Click Save Changes.
  10. Open your domain in a browser. You should see the site from the subfolder.

What the code does: the first line turns on rewriting. The next two lines check the domain name and make sure the request is not already in the subfolder. The last line quietly serves files from /mysite/.

If it does not work

  • Check for typing mistakes in the folder name.
  • Restore your backup copy.
  • Ask Hostvento support whether your plan allows .htaccess rules. Some setups need a different method.
Tip: A cleaner way is to change the domain's document root in your control panel, if it offers that option.

Quick recap

  • The document root is the folder a domain shows.
  • .htaccess can redirect requests into a subfolder.
  • Back up the file first.
  • Add the rewrite rules and save.
  • Test your domain.