[http到https的重定向,使用IIS 8.5中的URL重写模块

问题描述 投票:0回答:1

我正在尝试通过使用URL重写模块为整个站点设置从http到https的重定向。IIS版本8.5。但是,在web.config中应用了几种不同的设置后,我遇到了以下问题:

<rewrite>
        <rules>
            <clear />
            <rule name="Redirect to https" stopProcessing="true">
                <match url=".*" />
                <conditions>
                    <add input="{HTTP_X_FORWARDED_PROTO}" pattern="^http$" />
                    <add input="{HTTPS}" pattern="on" ignoreCase="true" />
                </conditions>
                <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" />
            </rule>
        </rules>
    </rewrite>

-以上使站点正常工作,但没有执行重定向

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

-这个重定向太多次

<rewrite>
        <rules>
            <rule name="HTTP to HTTPS redirect" stopProcessing="true">
                <match url="(.*)" />
                <conditions>
                    <add input="{HTTPS}" pattern="off" ignoreCase="true" />
                </conditions>
                <action type="Redirect" url="https://{HTTP_HOST}/{R:1}"
                    redirectType="Permanent" />
            </rule>
        </rules>
        <outboundRules>
            <rule name="Add Strict-Transport-Security when HTTPS" enabled="true">
                <match serverVariable="RESPONSE_Strict_Transport_Security"
                    pattern=".*" />
                <conditions>
                    <add input="{HTTPS}" pattern="on" ignoreCase="true" />
                </conditions>
                <action type="Rewrite" value="max-age=31536000" />
            </rule>
        </outboundRules>
    </rewrite>

-结果错误

 <rewrite>
        <rules>
            <rule name="http to https" stopProcessing="true">
                <match url="(.*)" />
                <conditions>
                    <add input="{HTTPS}" pattern="^OFF$" />
                </conditions>
                <action type="Redirect" url="https://www.something.net/{R:1}" redirectType="SeeOther" />
            </rule>
        </rules>
    </rewrite>

-都不起作用

有什么想法吗?

asp.net web-config iis-8
1个回答
0
投票

您可以使用以下规则:

 <configuration>
 <system.webServer>
 <rewrite>
 <rules>
 <rule name="HTTP to HTTPS" enabled="true" stopProcessing="true">
 <match url="(.*)" />
 <conditions>
 <add input="{HTTPS}" pattern="off" />
 </conditions>
 <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" />
 </rule>
 </rules>
 </rewrite>
 </system.webServer>
</configuration>

enter image description here

enter image description here

请确保已正确配置https绑定,并且已安装URL重写模块。

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.