gpt4 book ai didi

url-rewriting - 在 IIS URL Rewrite 2.0 中,为什么 HTTP_HOST 包含端口号?

转载 作者:行者123 更新时间:2023-12-04 07:03:06 28 4
gpt4 key购买 nike

我正在尝试使用 IIS URL Rewrite 2.0在 Windows 8.1 上使用 IIS 8.5。根据 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}为我解决了这个问题。

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

关于url-rewriting - 在 IIS URL Rewrite 2.0 中,为什么 HTTP_HOST 包含端口号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19257193/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com