【问题标题】:URL rewrite http to https but not on standard 443 portURL 将 http 重写为 https 但不在标准 443 端口上
【发布时间】:2015-06-03 16:54:34
【问题描述】:

我想使用 IIS 8.5 中的 URL 重写模块将任何非 https 流量从 http://something.com:112 重定向到 https://something.com:444(请注意,这些不是标准的 http 和 https 端口号)。

我尝试使用此重写规则,但它不起作用:

<rewrite>
<rules>
    <rule name="Redirect to HTTPS" stopProcessing="true">
    <match url="(.*)" />
    <conditions logicalGrouping="MatchAny">
        <add input="{HTTPS}" pattern="^OFF$" />
        <add input="{SERVER_PORT}" pattern="^444$" negate="true" />
    </conditions>
    <action type="Redirect" url="https://{HTTP_HOST}:444/{R:1}" redirectType="Found" />
    </rule>
</rules>
</rewrite>

我在失败的请求日志中得到的错误是:

模块名称 IIS Web 核心 通知 MAP_REQUEST_HANDLER Http状态 404 未找到 HttpReason HttpSubStatus 0 ErrorCode 系统找不到指定的文件。 (0x80070002)

我做错了什么?

【问题讨论】:

  • 小更新,在 Safari 浏览器中,我终于可以确定 URL 正在更改为 something.com:112:444。如何从最终到达网址中取出“:112”?

标签: url-rewrite-module iis-8.5


【解决方案1】:

我找到了答案,我错误地使用了 HTTP_POST,它包含 SERVER_NAME 和 HTTP_PORT。相反,我使用了这个动作,它似乎工作得很好:

我还注意到我不需要同时检查这两种情况。这个实际上可以满足我的需要,因为我们有一些网站在其他 https 端口上运行:

<rewrite>
      <rules>
        <rule name="Redirect to HTTPS on port 444" stopProcessing="true">
          <match url="(.*)" />
          <conditions>
            <add input="{HTTPS}" pattern="^OFF$" />
          </conditions>
          <action type="Redirect" url="https://{SERVER_NAME}:444/{R:1}" redirectType="Found" />
        </rule>
      </rules>
</rewrite>

【讨论】:

    猜你喜欢
    • 2020-04-23
    • 2019-02-02
    • 1970-01-01
    • 2011-07-28
    • 2014-09-20
    • 2011-06-02
    • 2012-02-28
    • 2014-03-04
    • 1970-01-01
    相关资源
    最近更新 更多