【问题标题】:Rewrite rule not working for redirection from http to https重写规则不适用于从 http 到 https 的重定向
【发布时间】:2019-08-03 01:19:36
【问题描述】:

尝试了下面的代码但它不起作用,在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>

【问题讨论】:

  • 您能否向我们提供您的完整 Web.config,删除任何敏感信息?
  • 你在IIS中安装了URL重写模块吗?
  • @MatthewEvans 我已经在 IIS 中安装了 URL 重写模块并且已经配置了它
  • @ColinM 这是来自网络配置的示例代码:...rule ...
  • 第一件事,把它放在你的问题中,而不是评论中。其次,您是否尝试过通过 IIS 管理控制台 -> URL Rewrite 配置此规则?

标签: c# iis url-rewrite-module


【解决方案1】:

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

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

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

问候, 哈尔帕。

【讨论】:

    猜你喜欢
    • 2020-04-29
    • 2013-06-02
    • 1970-01-01
    • 1970-01-01
    • 2015-12-26
    • 2018-09-10
    • 1970-01-01
    • 2015-08-10
    相关资源
    最近更新 更多