首页 > 解决方案 > 重写规则不适用于从 http 到 https 的重定向

问题描述

尝试了下面的代码,但它不起作用,在 c# 的 web.config 文件的 system.webServer 标签中输入了 rewrite 标签,显示错误 rewrite can not be child element of system.webServer 标签,我也在 IIS 中配置了这个规则

<configuration>
<system.webServer>
    <rewrite>
          <rules>
            <rule name="Rule1" 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>

标签: c#iisurl-rewrite-module

解决方案


如果没有使用 Web 平台安装程序安装 Urlrewrite 模块,请安装它,并尝试使用 urlrewrite 模块手动添加规则。

https://www.iis.net/downloads/microsoft/web-platform-installer

https://www.iis.net/downloads/microsoft/url-rewrite

问候,贾尔帕。


推荐阅读