Root redirection to subdirectory

Tonny FuseinIn a previous post we showed you how to force a normal HTTP call to HTTPS. Today we’ll show you how to redirect from root to subdirectory.

The default page/homepage in your root directory would normally be displayed when someone makes an HTTP request to your site. But what if you installed an application in a subdirectory and want to use that application as a starting point? For example, WordPress is installed in a subdirectory, and you want the WordPress application to be the default starting point when someone types your URL.

There is sample code available in our Knowledge Base to redirect using .NET code. This requires the page to load and compile before the redirection happens. Now I want to show you redirection using the IIS manager/web.config instead. This should redirect the request faster as the redirection happens as soon as the HTTP request received by IIS.

Using IIS7 manager, connect to IIS and navigate to the URL rewrite module. Add a blank rule and name it as you wish. Only two variables are needed; match URL pattern and actions.

The parameters are as follows:

Match URL section:
Requested URL : Matches the pattern
Using : Regular Expression
Pattern : ^$

Action section:
Action Type : redirect
redirect URL : your relative subdirectory path e.g., if nopCommerce is installed in a subdirectory you would use /nopCommerce
redirect type : permanent


This will write to your web.config and add this section:

<rule name="redirect" stopProcessing="true">
<match url="^$" />
<action type="RedirectToSubdir" url="/nopCommerce" />

That’s all there is to it.

Remember than any changes you make with IIS Manager are written to web.config, so overwriting web.config in the future can remove those changes.

12 thoughts on “Root redirection to subdirectory

  1. we want to install a wordpress blog and was told it needs to be a subdomain =http:// – can we do a 301 redirect to resolve to:

  2. If I just add that code directly to web.config does it matter where I put it (assuming I’m not breaking other code).

    1. It does. Each tag nested on particular tag, as long as you follow the proper format you should be fine.

  3. I am testing the site using discount asp Alternative url .is this suppose to work with alternative url because it is not?I don’t want to point to discounts asp nameserver until i am sure it works

  4. Pingback: Setting up HAP URL

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.