除主页之外的每个页面上的IIS服务器web.config HTTPS?

时间:2013-10-27 19:38:48

标签: iis url-rewriting https web-config

我在IIS服务器上运行了ExpressionEngine安装。目前我正在使用重写规则,强制网站在每个页面上使用HTTPS协议。我想改变它,以便它在除主页之外的每个页面上使用HTTPS。不幸的是,我对web.config重写规则知之甚少。提前谢谢!

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <clear />
                <rule name="Redirect to HTTPS" stopProcessing="true">
                  <match url="(.*)" />
                  <conditions>
                    <add input="{HTTPS}" pattern="^OFF$" />
                  </conditions>
                  <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

1 个答案:

答案 0 :(得分:1)

如果您不想将重定向规则应用于您的主页,则需要添加条件并过滤主页网址。它应该是这样的:

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