繁体   English   中英

IIS URL-重写:HTTP到HTTPS

[英]IIS URL-Rewrite: HTTP to HTTPS

我有一些网站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部分和任何args。

如何解决这个问题?

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&page=2 我做错了什么?

使用此规则完成:

<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>

适用于子网站。

<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部分

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM