0

Posted by Michael Alfaro on February 6, 2012

IIS7 URL Rewrite Module – User Friendly URLs

If you’re looking to write User friendly URLs off of IIS7, the rewrite module has a simple template to help you achieve it.  Here’s the source: http://learn.iis.net/page.aspx/497/user-friendly-url—rule-template/

“Using rule template to generate rewrite rules

The “User Friendly URL” rule template can be used to generate rewrite, redirect and outbound rules that make URLs for your dynamic web application more user and search engine friendly. Typically, dynamic web pages take into account query string parameters when generating an output HTML. The URLs with query strings (e.g. http://contoso.com/articles.aspx?year=2008&month=11) are not as easy for humans to use and communicate as simple hierarchy based URLs (e.g. http://contolso.com/articles/2008/11). In addition some search engine crawlers may ignore the query string when indexing the web site pages. The rule template helps you generate rewrite rule that transform the hierarchy based URLs to URLs with query strings. The templace can also, optionally, generate a redirect rule that can be used to redirect web clients form URLs with query strings to clean URLs. Finally, it is possible to create an outbound rewrite rule that replaces all the occurrences of URLs with query strings in the HTML responce with their hierarchy based URL equivalents.

To use the template follow these steps:

  1. Go to IIS Manager
  2. Select “Default Web Site”
  3. In the Feature View click “URL Rewrite“


  4. In the “Actions” pane on right hand side click on “Add rules…” and then select “User Friendly URL” template:


  5. In the “Add rules to enable user friendly URLs” dialog enter an example of an URL with query string parameters: http://localhost/article.aspx?id=123&title=some-title and then expand the drop down list with suggested options for how that example URL can be transformed into a URL without query string.



  6. Choose the second option: http://localhost/article/123/some-title. Notice that the URL pattern and Substitution URL have been updated accordingly. These will be used in the rewrite rule that will be created by the rule template. Check the “Create corresponding redirect rule” to create a redirect rule that will be used, when web clients used internal URL to request a web page. Those clients will be redirected to a corresponding public URL.
    Also, check the “Create corresponding outbound rewrite rule” to create an outbound rule that will replace all instances of internal URLs in the response HTML with their public equivalents.


  7. Click “OK” so that the rewrite, redirect and outbound rules will be generated:”

Topics: , ,

Add a Comment