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.)?$
RewriteCond %{REQUEST_URI} !^/subdirectory/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /subdirectory/$1
RewriteCond %{HTTP_HOST} ^(www.)?$
RewriteRule ^(/)?$ subdirectory/index.html [L]

Make sure to update the bold areas (“” 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.
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

16 thoughts on “How to Redirect Primary Domain to a Subdirectory

  1. Great article. It was inspiring, however, I did not succeed I redirecting my website.
    Until now when using drupal7/9 I copied all subfolders and files in the root.
    Now I have created drupal9 site using composer and the stricter changed. On localhost I can open site from http://localhost/sitename/web/.
    Webhosting provider does not allow webhosting redirect directly to subfolderis there way how to change opening website not from root bud from subfolder, so that site was iopning from not
    Thank you

    1. Hi Libor, it sounds like you’re trying to set up a parked domain or alias. While the linked article should be applicable for most cPanel based accounts, the specifics can vary from host to host. While we cannot provide troubleshooting for the specifics of other hosting, we hope that helps narrow things down for you!

  2. So, this is redirecting, but showing the subdomain in the address bar. How do I point the primary domain to a subdirectory as the main website? I want the subdomain WordPress as the primary domain site.

    1. Hello RY Design,

      Thank you for your question. It sounds like you are trying to change the document root for your site. If you are on a shared server, you will need to ask our Support team to change the document root for your primary domain from public_html to the desired folder. If you are on a VPS or Dedicated server, you can change this via WHM.

      Best Regards,
      Alyssa K.

    1. Hello, and sorry to hear that you’re running into issues with the redirect.

      If that is happening, it is most likely that the code in .htaccess is still using the placeholder information in the example.

      When you add the code to your .htaccess file, please be sure to change the placeholder information to your actual site’s domain name and subdirectory. Hope that helps!

  3. Does it affect google ranking ? 0r google will treat it similarly as we open the default root page(index.html).

    1. Hello and thanks for contacting us. Did you make sure to replace “” and “subdirectory” appropriately? Also, did you put an index file in the new directory?

  4. i did this but on navigation when i click on ther page it is not showing. instead of it shows
    Please help me to get rid of this problem.

    1. Sorry for the troubles. I check the article and the code block was not displaying correctly. I have updated it to show the correct rewrite rules, and they should work now.

    1. No, the only difference is when you use the cPanel redirect tool it automatically adds the above rules to the .htaccess file for you.

      Thank you,

Was this article helpful? Join the conversation!

Shop the Black Friday Sale
Hurry! These Deals Won't Last Long