#Smalig #ISAPI url #rewrite in IIS 7/8
During an upgrade of my server from Windows 2008 / IIS 7 to Windows 2012 , one ISAPI url rewrite that I used did not work. The ISAPI filter appears to be obsolete and unmaintained, so I decided to try and write my own using IIS url rewrite rules, and it turned out to be really easy.
So, the premise of this url rewrite is to make a SEO unfriendly url like abc.aspx?id=10 into /web/id/10/abc.aspx – which is more SEO friendly. The smalig Url rewrite will work with any number of parameters, and this is designed to work with at most 2, but you can expand it, if you have more parameters in your url.
<system.webServer>
<security>
<requestFiltering allowDoubleEscaping=”true”/>
</security>
<rewrite>
<rules>
<rule name=”smalig1″>
<match url=”web/([^/]+)/([^/]+)/([^/]+).aspx” />
<action type=”Rewrite” url=”/{R:3}.aspx?{R:1}={R:2}” logRewrittenUrl=”true” />
</rule>
<rule name=”smalig2″>
<match url=”web/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+).aspx” />
<action type=”Rewrite” url=”/{R:5}.aspx?{R:1}={R:2}&{R:3}={R:4}” logRewrittenUrl=”true” />
</rule>
</rules>
</rewrite>
</system.webServer>
The “Allow Double escaping” bit, allows for urls with a plus symbol in them, and if you don’t have this, then you can remove this security exception.