[英]URL Rewrite IIS 7.5 - only for port 80
我设置 IIS 使用 Z5DA5ACF4661B4EFB217E6 中的重写向导将非 https 流量重定向到 https。 我按照此处概述的步骤操作: https://www.namecheap.com/support/knowledgebase/article.aspx/9953/38/iis-redirect-http-to-https 。
现在我想添加一个条件来说明 {server_port} = 80。
我添加了一个新条件:
条件输入:{Server_Port}
检查输入字符串:是否匹配模式
图案:80
在条件下:逻辑分组:匹配所有
然后我保存了规则并重新启动了 IIS。
我仍然将所有到我网站的流量重定向到 https,它抛出错误代码:SSL_ERROR_RX_RECORD_TOO_LONG,因为https ://www.mysite.Z4D236D9A2D102C5FE6AD1C 不计算。
仅当服务器端口为 80 时,如何编写重定向条件?
请注意,我没有在 web.config 中写下我的重定向,我之所以问,是因为我发现的大多数示例都讨论了 web.config。 我确实找到了一个应该可以工作的 web 配置示例,但我不知道如何使用重写工具来实现它:
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
<add input="{SERVER_PORT}" pattern="XXXX" negate="true" />
</conditions>
<action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
</rule>
我发现您的规则条件中的简单错误是<add input="{SERVER_PORT}" pattern="XXXX" negate="true" />
negate="true"表示它与模式不匹配,它重定向到 https。 要阻止您的 requiremnet,您可以使用 bwlow 规则:
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" />
<add input="{SERVER_PORT}" pattern="80" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Found" />
</rule>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.