重写HTTP到HTTPS重定向的规则

时间:2017-02-04 17:52:37

标签: url-redirection

我正在尝试将所有http://thesite.comhttp://www.thesite.comhttps://thesite.com重定向到https://www.thesite.com。但我没有正确的模式。我做错了什么?

<rewrite>
    <rules>
        <rule name="Redirect to HTTPs" enabled="true" stopProcessing="true">
            <match url="(.*)" />
            <conditions>
                <add input="{HTTPS}" pattern="OFF" />
            </conditions>
            <action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{R:1}" />
        </rule>
    </rules>
</rewrite>

1 个答案:

答案 0 :(得分:0)

我找到了解决方案:

           <rule name="Redirect non-www OR non-https to https://www">
                <match url=".*" />
                <conditions logicalGrouping="MatchAny">
                    <add input="{HTTP_HOST}" pattern="^thesite.com$" />
                    <add input="{HTTPS}" pattern="off" />
                </conditions>
                <action type="Redirect" url="https://www.thesite.com/{R:0}" redirectType="Permanent"/>
            </rule>