Search code examples
http-redirectiismodel-view-controllerhttp-status-code-301

asp.net MVC And I need to setup 301 redirects


I have a site moving from php to asp.net MVC And I need to setup 301 redirects for it so like www.mystoresitem.com/products/widget1name needs to redirect to www.mystoresitem.com/widget1name for 700+ different widgets how do I redirect this with out doing it for each product/widget.


Solution

  • First of all you need to be sure that you installed URL Rewrite module in your IIS

    Then in your web.config just add this rules inside system.webServer section:

    <rewrite>
        <rules>
            <rule name="Redirects to products">
                <match url="^products/(.*)" />
                <action type="Redirect" url="/{R:1}" />
            </rule>
        </rules>
    </rewrite>
    

    It will automatically redirect all your urls

    www.mystoresitem.com/products/{productname} to www.mystoresitem.com/{productname}