IIS URL Rewrite ASP

If you want to use regular expressions you could do something like this

<rule name="RewriteUserFriendlyURL1" stopProcessing="true">
     <match url="^([^/]+)/([^/]+)/?$" />
         <conditions>
             <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
             <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
         </conditions>
     <action type="Rewrite" url="default.asp?language={R:1}&amp;id={R:2}" />
</rule>

This would rewrite “domain.com/en/service” as “domain.com/default.asp?language=en&id=Service”, or “domain.com/2/3” as “domain.com/default.asp?language=2&id=3”

To change the 2 to en and the 3 to service, along with all the other options though I think you would need a separate rule for each permutation, or have some sort of logic within your asp pages to read your querystring variables and send the corresponding values to your SQL queries. Note also that the parameters in the friendly url appear in the same order and the querystring variables in the rewritten URL, although this shouldn’t really be an issue. If someone tries to access the page with the original “unfriendly” url they will find what they are looking for, whichever way round they enter the querystring variables.

Please note, I didn’t actually hand code the rule above, I generated it with the URL Rewrite module in IIS manager – it makes life a lot easier

Also note, as discussed with my namesake in the other answer, this only applies to IIS7 and above

Leave a Comment