Search code examples
asp.netiisweb-confighttp-redirect

simple redirect from one page to another in web.config


I'm using Asp.Net web forms with IIS 8.5.

I already have url routing in place and setup httperrors in web.config to catch 404/500 errors, but I now need to redirect some old pages to a new destination.

The old page will no longer exist, so it must not be caught by the HttpErrors code before it can be redirected.

I want to redirect a page from /widgets/oldwidget to /newwidget

Note: /newwidget is the rerouted url, the physical page will be something like: /pages/oldwidget.aspx.

I'm struggling difficult to find clear instructions as to how to use httpdirect in this scenario.

Anyone offer any advice? Is this the right approach?

 <httpRedirect enabled="false" httpResponseStatus="Permanent" exactDestination="true">
     // Redirect my page
 </httpRedirect>

<httpErrors errorMode="DetailedLocalOnly">
    <clear/>
    <remove statusCode="404" subStatusCode="-1"/>
    <remove statusCode="500" subStatusCode="-1" />
    <error statusCode="404" path="/404" responseMode="ExecuteURL" />
    <error statusCode="500" path="/500" responseMode="ExecuteURL" />
</httpErrors>

Solution

  • According to your description, I suggest you could try to use url rewrite to achieve your requirement.

    You could install the url rewrite extension on this url.

    Then you could add below config setting in the config file.

    <system.webServer>