首页 > 解决方案 > Web 配置重写规则以在多租户应用程序上强制 http 到 https

问题描述

我有一个多租户门户系统,但重写规则不适用于多种条件

<rule name="HTTP to HTTPS redirect" stopProcessing="true">
        <match url="^(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
<add input="{HTTPS1}" pattern="^(website1\.com|www\.website1\.com)$" />
<add input="{HTTPS2}" pattern="^(website2\.com|www\.website2\.com)$" />
<add input="{HTTPS3}" pattern="^(website3\.com|www\.website3\.com)$" />
<add input="{HTTPS4}" pattern="^(website4\.com|www\.website4\.com)$" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{R:1}" />

    </rule>

我希望当我在我的网络浏览器上访问http://portal.website1.com时,该程序应该将我带到https://portal.website1.com并为 portal.website2.com、门户做同样的事情。 website3.com,portal.website4.com

但它仅适用于 portal.website2.com 和 portal.website3.com ,它不会在 portal.website1.com 和 portal.website4.com 上强制使用 https

标签: asp.net

解决方案


试试这个system.WebServer

 <system.webServer>
....

    <rewrite>
            <rules>
                <rule name="Force HTTPS" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
                    <match url="*" />
                    <conditions logicalGrouping="MatchAny">
                        <add input="{HTTPS}" pattern="off" />
                    </conditions>
                    <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URO}" redirectType="Temporary" />
                </rule>
            </rules>
        </rewrite>
  </system.webServer>

推荐阅读