Я пытаюсь использовать перезапись URL-адресов IIS 2.0 с IIS 8.5 в Windows 8.1. Согласно Доступ к частям URL из Переписать правило,
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.
Чтобы проверить это, вот правило, которое я использовал:
<rule name="Test" stopProcessing="true">
<action type="Redirect" url="http://localhost/?{HTTP_HOST}" redirectType="Temporary" />
</rule>
Затем я использовал вкладку Composer в Fiddler, чтобы создать следующий запрос:
http://localhost.localdomain:65352/
на что IIS ответил
HTTP/1.1 307 Moved Temporarily
Location: http://localhost/?localhost.localdomain:65352
Из этого мы видим, что номер порта включен в переменную HTTP_HOST, в отличие от документации, указанной выше. Это усложняет мои правила сопоставления, потому что тогда я должен учитывать необязательное наличие номера порта. Как мне просто получить имя хоста без номера порта?