Web.config 将规则 http 重写为 https 和 angular 路由组合

Web.config rewrite rule http to https and angular route combination

我在 IIS 中为 angular 应用程序设置了以下重写规则:

<rewrite>
    <rules>
        <rule name="Angular Routes1" enabled="true" stopProcessing="true">
            <match url=".*" />
            <conditions logicalGrouping="MatchAll">
                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
            </conditions>
            <action type="Rewrite" url="index.html" />
        </rule>
        <rule name="HTTPS Redirect" stopProcessing="true">
            <match url="(.*)" />
            <conditions>
                <add input="{HTTPS}" pattern="^OFF$" />
            </conditions>
            <action type="Redirect" url="https://www.example.com{REQUEST_URI}" appendQueryString="false" />
        </rule>
    </rules>
</rewrite>

当有人浏览 http://www.example.com, its being redirected to https://www.example.com,但当我使用设置网站的路径时,例如:

http://www.example.com/layout/dark it is not redirecting to https://www.example.com/layout/dark

我在想是不是我添加两条规则时出错了,应该全部添加到一条规则中。

谢谢。

您可以先把http转https规则放上再试。如果还是不行,可以使用failed request tracking查看详细错误原因。

Using Failed Request Tracing to Trace Rewrite Rules.