In the IIS Rewrite 2.0 URL, why does HTTP_HOST include the port number?

I am trying to use IIS URL Rewrite 2.0 with IIS 8.5 on Windows 8.1. According to Access to parts of the URL from the rewrite rule ,

For an HTTP URL in this form: http(s)://<host>:<port>/<path>?<querystring>

• The <path> is matched against the pattern of the rule.
• The <querystring> is available in the server variable called QUERY_STRING and can be accessed by using a condition within a rule.
• The <host> is available in the server variable HTTP_HOST and can be accessed by using a condition within a rule.
• The <port> is available in the server variable SERVER_PORT and can be accessed by using a condition within a rule.
• Server variables SERVER_PORT_SECURE and HTTPS can be used to determine if a secure connection was used. These server variables can be accessed by using a condition within a rule.
• The server variable REQUEST_URI can be used to access the entire requested URL path, including the query string.

To test this, here is the rule I used:

<rule name="Test" stopProcessing="true">
  <action type="Redirect" url="http://localhost/?{HTTP_HOST}" redirectType="Temporary" />
</rule>

Then I used the Composer tab in Fiddler to create the following query:

http://localhost.localdomain:65352/

to which IIS answered

HTTP/1.1 307 Moved Temporarily
Location: http://localhost/?localhost.localdomain:65352

This shows that the port number is included in the HTTP_HOST variable, contrary to the documentation mentioned above. This adds some complexity to my matching rules, because then I have to consider the optional presence of a port number. How do I get a host name without a port number?

+4
source share
1

, , ; , {SERVER_NAME} {HTTP_HOST} .

: https://serverfault.com/a/418530/3495

+3

All Articles