Friday, 20 January 2012

IIS URL Rewrite Module Configuration Reference

What is URL Rewrite Module


The URL Rewrite Module rewrites request URLs to simple, user-friendly, and search-engine friendly addresses that are displayed to users or in Web applications. URL Rewrite uses defined rules to evaluate and then map the request URL to the address defined in the rule before it is processed by an IIS Web server. You can define URL rewriting logic that includes regular expressions and wildcards, and rules can be applied based on the request URL, HTTP headers, and server variables. While the primary purpose of the module is to rewrite request URLs to more friendly URLs, you can also use the module to define rules that perform redirects, send custom responses, or abort requests.

URL Rewrite Module Overview



A rewrite rule defines the logic of what to compare or match the request URL with, and what to do if the comparison is successful.

Rewrite rules consists of the following parts:


  • Pattern – The rule pattern is used to specify either the regular expression or a wildcard pattern that is used to match URL strings.

  • Conditions – The optional conditions collection is used to specify additional logical operations to perform if a URL string matches the rule pattern. Within the conditions, you can check for certain values of HTTP headers or server variables, or verify if the requested URL corresponds to a file or directory on a physical file system.

  • Action – The action is used to specify what to do if the URL string matches the rule pattern and all the rule conditions are met.



Click here to read the full reference from learn.iis.net.

Using server variables in rewrite rules



Server variables provide additional information about current HTTP requests. You can sue this information to make rewriting decisions or to compose the rewritten URL.

Using back-references in rewrite rules



Parts of rules or conditions inputs can be captures in back-references. These can be then used to construct substitution URLs within rules actions or to construct input strings for rule conditions.

Back-references are generated in different ways, depending on which kind of pattern syntax is used for the rule. When an ECMAScript pattern syntax is used, a back-reference can be created by putting parenthesis around the part of the pattern that must capture the back-reference. For example, the pattern ([0-9]+)/([a-z]+)\.html will capture 07 and article in back-references from this requested URL: 07/article.html.

Using String functions in rewrite rules



There are three string functions available for changing the values within a rewrite rule action, as well as any conditions:

ToLower - returns the input string converted to lower case.
UrlEncode - returns the input string converted to URL-encoded format. This function can be used if the substitution URL in rewrite rule contains special characters (for example non-ASCII or URI-unsafe characters).
UrlDecode - decodes the URL-encoded input string. This function can be used to decode a condition input before matching it against a pattern.

The functions can be invoked by using the following syntax:
{function_name:any_string}

Where "function_name" can be on eof the following: "ToLower", "UrlEncode", "UrlDecode". "Any_string" can be either a literal string or a string built by using server variables or back-references. For example, the following are valid invocations of string functions:
{ToLower:DEFAULT.HTM}
{UrlDecode:{REQUEST_URI}}
{UrlEncode:{R:1}.aspx?p=[résumé]}

Rewrite maps



A rewrite map is an arbitrary collection of name-value pairs that can be used within rewrite rules to generate the substitution URL during rewriting. Rewrite maps are particularly useful when you have a large set of rewrite rules and all of these rules use static strings (that is, when there is no pattern matching used).

Click here to read the full reference from learn.iis.net.

1 comment:

  1. Hi, A diagram can be used to represent words, concepts or other items linked to and prepared around a central key word or idea about Web Design Cochin
    Web Design Cochin. Mind maps are used to generate, structure and visualise ideas to organize and make decisions in designing web sites. Thanks.....

    ReplyDelete