配置 web.config 使 HTTP 访问自动重定向到 HTTPS(SSL)

作者:vkvi 来源:ITPOW(原创) 日期:2021-8-28
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="http to https" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{HTTP_HOST}" pattern="www.itpow.com" />
                        <add input="{HTTPS}" pattern="^OFF$" />
                    </conditions>
                    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

如上 QueryString 也是自动带过去的。

可直接在 IIS 中配置,也可直接在 web.config 中配置,因为 IIS 中配置,最终也是写入 web.config 的。

相关文章