正则表达式语法在 Web.Configre 重写中无效

Regex Syntax is invalid in Web.Configre rewrite

谁能告诉我为什么我的正则表达式在这里不起作用?

    <rule name="Redirect to http" stopProcessing="true">
      <match url="^(?i)\Q/\Ehome\Q/\E?private$" ignoreCase="true" />
      <action type="Redirect" url="http://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
    </rule>

当我添加此脚本时,出现 HTTP 500.22 错误;

The expression ^(?i)\Q/\Ehome\Q/\E?private$ has syntax which is not valid.

您不需要 \Q/\E 运算符,因为斜杠不是特殊的正则表达式元字符。

你也不需要 (?i) 因为你使用 ignoreCase=true.

使用^/home/private$.