How to Redirect Primary Domain to a Subdirectory

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 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. However, VPS and Dedicated hosting customers with 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
  2. Choose File Manager under Files
  3. Edit 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 [L]

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.

Give your small business a digital presence with our fast, secure Shared Hosting solutions. Easily manage your websites with the industry-leading control panel on up to 20x faster web hosting that fits your budget.
Share this Article
CM
Christopher Maiorana Content Writer II

Christopher Maiorana joined the InMotion community team in 2015 and regularly dispenses tips and tricks in the Support Center, Community Q&A, and the InMotion Hosting Blog.

More Articles by Christopher