IIS 7 URL重写规则似乎只工作一次



我试图强制在IIS下运行的网站始终以https模式运行,并重定向到它的完整根名称,其中包括www,以便SSL证书正常工作

下面是网页。配置项:

<system.webServer>
    <rewrite>
        <rules>
            <clear />
            <rule name="Redirect to https" stopProcessing="true">
                <match url="(.*)" />
                <conditions>
                    <add input="{HTTPS}" pattern="off" ignoreCase="true" />
                    <add input="{HTTP_HOST}" pattern="^somewebsite.com$" ignoreCase="true"  />
                </conditions>
                <action type="Redirect" redirectType="Permanent" url="https://www.{HTTP_HOST}{REQUEST_URI}" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>

这适用于第一次请求,例如有人第一次在浏览器URI中请求:somewebsite.com,他们将自动重定向到https://www.somewebsite.com。然而,一旦站点被加载,如果用户手动删除浏览器URI中的www或https,服务器就不会执行后续的重定向。这是经过设计的吗?规则是否有可能一直执行?

这是我在所有活动SSL站点上使用的。我使用了两条规则,从来没有遇到过任何问题:

<rule name="Redirect domain.com to www" patternSyntax="Wildcard" stopProcessing="true">
    <match url="*" />
    <conditions>
        <add input="{HTTP_HOST}" pattern="domain.com" />
    </conditions>
    <action type="Redirect" url="https://www.domain.com/{R:0}" />
</rule>
<rule name="HTTP to HTTPS" stopProcessing="true">
    <match url="(.*)" />
    <conditions>
        <add input="{HTTPS}" pattern="^OFF$" />
    </conditions>
    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />
</rule> 

最新更新