我正在尝试使用IIS URL 重写 2.0 http://www.iis.net/downloads/microsoft/url-rewrite在 Windows 8.1 上使用 IIS 8.5。根据从重写规则访问 URL 部分 http://www.iis.net/learn/extensions/url-rewrite-module/url-rewrite-module-configuration-reference#Accessing_URL_Parts_from_a_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.
为了测试这一点,这是我使用的规则:
<rule name="Test" stopProcessing="true">
<action type="Redirect" url="http://localhost/?{HTTP_HOST}" redirectType="Temporary" />
</rule>
然后我使用 Fiddler 中的 Composer 选项卡创建以下请求:
http://localhost.localdomain:65352/
IIS 对此做出了回应
HTTP/1.1 307 Moved Temporarily
Location: http://localhost/?localhost.localdomain:65352
由此我们可以看到,端口号包含在 HTTP_HOST 变量中,这与上面引用的文档相反。这给我的匹配规则增加了一些复杂性,因为我必须考虑端口号的可选存在。如何只获取主机名而不获取端口号?
不幸的是,我无法告诉你为什么会发生这种情况;但我可以告诉你,使用{SERVER_NAME}
代替{HTTP_HOST}
为我解决了这个问题。
See: https://serverfault.com/a/418530/3495 https://serverfault.com/a/418530/3495
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)