---
title: "How to Redirect Primary Domain to a Subdirectory"
description: "By default, your primary domain document root is set as the public_html directory. This is where you can place live website files for serving to the web. Any files in this directory will be rendered..."
url: https://www.inmotionhosting.com/support/domain-names/how-to-redirect-your-primary-domain-to-a-subdirectory/
date: 2017-12-08
modified: 2021-08-16
author: "Christopher Maiorana"
categories: ["Domain Names"]
type: post
lang: en
---

# How to Redirect Primary Domain to a Subdirectory

![](https://www.inmotionhosting.com/support/wp-content/uploads/2021/07/How-to-Redirect-Your-Primary-Domain-to-a-Subdirectory-1024x538.png)

By default, your [primary domain document root](https://www.inmotionhosting.com/support/website/where-to-upload-files/) is set as the public_html directory. This is where you can place live website files for serving to the web. Any files in this directory will be rendered and served as part of a website.

However, in some cases, a situation may arise in which a document root change is needed. For shared servers, it is necessary to contact [Live Support](https://www.inmotionhosting.com/support/amp/how-to-get-great-technical-support/). However, VPS and Dedicated hosting customers with [root access](https://www.inmotionhosting.com/support/amp/obtain-root-access/) can use the steps mentioned in our full guide on Changing the Document Root for Your Domain. This is considered advanced server administration because it involves editing your Apache configuration.

In this article, we will show you an easier way to accomplish a document root change without requiring root access or editing your system’s configuration files. We will show you **how to redirect your primary domain to a subdirectory**. With the redirect code we provide below, users landing on your primary domain will be redirected to the contents of a subdirectory of your choice.

## How to Redirect to Subfolder

Follow along with the steps below to learn how to redirect to a folder:

1. [Log into cPanel](https://www.inmotionhosting.com/support/edu/cpanel/how-to-log-into-cpanel/)
2. Choose **File Manager** under *Files*
3. [Edit](https://www.inmotionhosting.com/support/website/how-to-edit-a-file/) the `.htaccess` file

Now you that you are editing the `.htaccess` file, add the following code to the file:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?**example.com**$
RewriteCond %{REQUEST_URI} !^/**subdirectory**/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /**subdirectory**/$1
RewriteCond %{HTTP_HOST} ^(www.)?**example.com**$
RewriteRule ^(/)?$ **subdirectory**/index.html

Make sure to update the bold areas ("example.com" and "subdirectory") with your own values unique to your site.

Make sure to **Save Changes** to the file when you're done.

---

Well done! You have completed this tutorial. Now, users landing on your domain will be redirected to the subdirectory you selected.
