Root redirection to subdirectory

On April 18, 2012, in How-to, Technical, by Tonny Fusein

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.


9 Responses to “Root redirection to subdirectory”

  1. Dimitri says:

    Good article.

    Also, it would be great to read some more detailed information about how to create a subdomain.

  2. Susan says:

    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:

  3. Bryan says:

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

    • Tonny says:

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

  4. nive says:

    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

Leave a Reply

iBlog by PageLines