iis - URL 重写 IIS 7.5 - 仅适用于端口 80

标签 iis url-rewriting

我使用 IIS 中的重写向导将 IIS 设置为将非 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.com:83不计算。

如何编写仅当服务器端口为 80 时才重定向的条件?

请注意,我没有在 web.config 中编写重定向,之所以询问,是因为我找到的大多数示例都讨论了 web.config。我确实找到了一个应该可以工作的网络配置示例,但我不知道如何使用重写工具来实现它:

<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。要阻止您的需求,您可以使用 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>

关于iis - URL 重写 IIS 7.5 - 仅适用于端口 80,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63137199/

相关文章:

.htaccess - 使用 .htaccess 更改 url 中的目录

.htaccess - 使用 .htaccess 从 URL 中删除 "/php/"子目录

.htaccess - nginx重写html文件并添加尾部斜杠

asp.net-core - ASP.NET Core 2.1 中不使用正则表达式的 URL 重写

iis - CORS 预检请求使用 Windows 身份验证返回 HTTP 401

IIS 7 URL 重写 - 403 错误

iis - 经典的 asp 和 IIS 应用程序池之间有什么关系?

json - 错误 404.3 未找到 JSON 文件

IIS 中的 Apache ProxyPass 和 ProxyPassReverse 等效项

iis - 如何在目录浏览中隐藏 web.config?