Friday, January 14, 2011

IIS URL Rewrite

Rewriting URL for IIS could be tricky. With the right tool, not any more. IIS URL Rewrite 2.0 module provides a friendly UI for web administrators to easily setup rules to define URL rewriting behavior. The tool can be downloaded from here. After installation, the URL Rewrite module will show up under web site IIS section.


 From here, select Add Rule(s)  action, and you can define rewrite rule using Rule Edit Template. For example, I want to rewrite URL from ~/promotion to ~/productionOrder.asxp?promotion=1,  I can define the rule this way: 


 
Apply the rule, you will find the web.config has been updated with the following settings:


     <system.webServer>
        ...
         <rewrite>
            <rules>
                <rule name="Redirect rule 1 for guestpass" stopProcessing="true">
                    <match url="^promotion$" />
                    <action type="Redirect" url="ProductionOrder.aspx?promotion=1" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>

Restart web site, the rule should take effect now.
 

No comments:

Post a Comment