【问题标题】:IIS URL-Rewrite: HTTP to HTTPSIIS URL 重写:HTTP 到 HTTPS
【发布时间】:2016-03-20 22:42:11
【问题描述】:

我有一些网站example.org,在上面我保留了example.com/project1example.com/project2 等子网站。我只需要在某些子站点上进行简单的HTTP→HTTPS 重定向,但不想手动将其写入代码文件中。

所以我为他找到了URL-Rewrite2 模块和规则:

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

它最多只能解决一个问题:它从http://example.com/project1 重定向到https://example.com/,因此它丢失了子站点URL 部分和任何参数。

如何解决这个问题?

UPD:使用此规则

    <rule name="Redirect to HTTPS" stopProcessing="true">
                        <match url="(.*)" />
                        <conditions>
                            <add input="{HTTPS}" pattern="^OFF$" />
                        </conditions>
                        <action type="Redirect" url="https://{HTTP_HOST}{UNENCODED_URL}" />
</rule>

除了参数重复之外,子站点通常会重定向。 http://example.com/project1?page=2 变成 https://example.com/project1?page=2&amp;page=2。我做错了什么?

【问题讨论】:

    标签: iis https url-rewriting url-routing url-rewrite-module


    【解决方案1】:

    使用此规则完成:

    <system.webServer>
      <rewrite>
                <rules>
                    <rule name="Redirect to HTTPS" stopProcessing="true">
                        <match url="(.*)" />
                        <conditions>
                            <add input="{HTTPS}" pattern="^OFF$" />
                        </conditions>
                        <action type="Redirect" url="https://{HTTP_HOST}{UNENCODED_URL}" appendQueryString="false" />
                    </rule>
                </rules>
            </rewrite>
      </system.webServer>
    

    在子网站上效果很好。

    【讨论】:

      【解决方案2】:
      <rewrite>
          <rules>
                  <rule name="Redirect to http" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
                      <match url="*" negate="false" />
                      <conditions logicalGrouping="MatchAny">
                          <add input="{HTTPS}" pattern="off" />
                      </conditions>
                      <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Found" />
                  </rule>
              </rules>
      

      将其添加到 system.webserver 部分

      【讨论】:

        猜你喜欢
        • 2012-07-23
        • 1970-01-01
        • 1970-01-01
        • 2013-02-02
        • 2015-08-12
        • 1970-01-01
        • 2012-10-13
        • 2012-02-28
        • 2016-02-26
        相关资源
        最近更新 更多