【问题标题】:IIS Re-write http to https with subfoldersIIS 使用子文件夹将 http 重写为 https
【发布时间】:2015-11-16 01:48:42
【问题描述】:

尽管听起来很简单,而且我搜索过很多,但我无法得到

http://example.com/subfolder 使用 IIS 重写重定向到 https://example.com/subfolder

注意:这仅适用于浏览器中明确声明“http”的情况。

<rule name="HTTP to HTTPS redirect" stopProcessing="true">
                <match url="(.*)" />
                <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                    <add input="{HTTPS}" pattern="off" />
                </conditions>
                <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Found" />enter code here

谢谢!

【问题讨论】:

标签: http redirect iis rewrite subdirectory


【解决方案1】:

您的规则的问题是重定向操作中的 REQUEST_URI 是请求的整个 URI。你想要的是规则匹配的结果。 R1 会给你这个。 This answer gives a good explanation of the rule back-references。可以这样构造一个工作规则:

<rewrite>
  <rules>
    <rule name="HTTP to HTTPS Redirect" enabled="true" stopProcessing="true">
    <match url="(.*)" />
    <conditions>
      <add input="{HTTPS}" pattern="off" ignoreCase="true" />
    </conditions>
    <action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{R:1}" />
    </rule>
  </rules>
</rewrite>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-09-07
    • 1970-01-01
    • 2013-10-16
    • 2013-05-02
    • 2023-04-07
    • 2017-08-24
    • 2016-09-23
    • 1970-01-01
    相关资源
    最近更新 更多