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 部分和任何参数。

如何解决这个问题?

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