Using Server Variables

Updated: November 6, 2009

Applies To: Windows 7, Windows Server 2008, Windows Server 2008 R2, Windows Vista

Server variables provide additional information about current HTTP requests. You can use the information in server variables as part of the rewriting logic or to help when you compose the rewritten URL. Within rewrite rules, server variables can be referenced in the following locations.

  • In the condition input string.

  • In rule substitution strings, specifically in the URL attribute of the Rewrite and Redirect actions, and in the statusLine and responseLine of the CustomResponse action.

Server variables can be referenced by using the {VARIABLE_NAME} syntax. For example, the following condition uses the QUERY_STRING server variable.

<add input="{QUERY_STRING}" pattern="id=([0-9]+)"/>

You can also use server variables to access HTTP headers from the current request. Server variables are generated from the HTTP headers in the current request according to the following convention.

  • All dash ("-") symbols in the HTTP header name are converted to underscore symbols ("_").

  • All letters in the HTTP header name are converted to uppercase.

  • The "HTTP_" prefix is added to the header name.

For example, in order to access the HTTP header "user-agent" from a rewrite rule, you can use the {HTTP_USER_AGENT} server variable.

See Also

Community Additions

ADD
Show: