【问题标题】:Rewrite rule error: HTTP Error 500.50 - URL Rewrite Module Error. The expression "https://abc.com/{R:1}" cannot be expanded重写规则错误:HTTP 错误 500.50 - URL 重写模块错误。无法展开表达式“https://abc.com/{R:1}”
【发布时间】:2011-10-18 11:41:24
【问题描述】:

每当有人通过 HTTP 协议发出请求时,我都会重写 url 以使其成为 HTTPS。这是 web.config 中的代码:

<rule name="Imported Rule 1-1" enabled="true" stopProcessing="true">
    <match url="^(?!https://).*" ignoreCase="false" />
    <conditions logicalGrouping="MatchAll">
        <add input="{SERVER_PORT}" pattern="80" ignoreCase="false" />
    </conditions>
    <action type="Rewrite" url="https://abc.com/{R:1}" />
</rule> 

但是当我在 http:// 上浏览时,我得到 IIS 错误

HTTP 错误 500.50 - URL 重写模块错误。表达式"https://abc.com/{R:1}" 无法展开。

我该如何解决这个问题?我完全糊涂了。

【问题讨论】:

  • 我现在也收到了。你有没有找到解决办法?如果是,请在此处发布。
  • 附言。您可以在match 中使用negate="true"

标签: asp.net iis url-rewriting iis-7 url-rewrite-module


【解决方案1】:

匹配是从零开始的。

<action type="Rewrite" url="https://abc.com/{R:1}" />

行不通,因为您只有一场比赛。你需要:

<action type="Rewrite" url="https://abc.com/{R:0}" />

另外,这也行不通,因为您只能在站点根目录下的路径上进行匹配。

<match url="^(?!https://).*" ignoreCase="false" />

您似乎正在检查 ssl。试试这个:

      <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
        <add input="{HTTPS}" pattern="^OFF$" />
      </conditions>

【讨论】:

  • 虽然匹配是从零开始的,但第一个匹配 {R:0} always 包含匹配的完整字符串,第二个匹配 {R:1} 匹配 first 在{R:0} 中捕获组。所以,这个答案在第一部分是不正确的。您可以在“测试模式”对话框中亲自查看。
【解决方案2】:

您可以通过网络配置重定向到 希望对大家有帮助

<rule name="Redirect to WWW" stopProcessing="true">
  <match url=".*" />
     <conditions>
       <add input="{HTTP_HOST}" pattern="^abc.com$" />
     </conditions>
  <action type="Redirect" url="http://www.abc.com/{R:0}" redirectType="Permanent" />
</rule>

【讨论】:

    猜你喜欢
    • 2012-12-22
    • 2018-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-24
    • 2015-11-27
    相关资源
    最近更新 更多