URL Parts available to URL Rewrite Rules

URL Rewrite is a powerful URL rewriting tool available for IIS7 and newer.  Your rewriting options are almost unlimited, giving you the ability to optimize URLs for search engine optimization (SEO), support multiple domain names on a single site, hiding complex paths and much more.

URL Rewrite allows you to use any Server Variable as conditions, and with URL Rewrite 2.0, you can also update them on the fly.  To see all variables available to your site, see this post.

An understanding of the parts of a complete URL are essential to working with URL Rewrite, so I’ll include the basics here.  Ruslan Yakushev’s configuration reference was my authoritative source for this.

Take this URL for example:

image

The URL is http://www.bing.com/search?q=IIS+url+rewrite

The parts of the URL are: http(s)://<host>:<port>/<path>?<querystring>

Part Example Server Variable
http(s) http SERVER_PORT_SECURE or HTTPS = on/off
<host> www.bing.com HTTP_HOST
<port> Default is 80 SERVER_PORT
<path> search The rule pattern in URL Rewrite
<path> /search PATH_INFO
<querystring> q=IIS+url+rewrite QUERY_STRING
entire URL path with querystring /search?q=IIS+url+rewrite REQUEST_URI

It’s important to note that /, : and ? aren’t included in some of the server variables. Understanding which slashes are included is important to creating successful rules.

No Comments