【问题标题】:What is the proper regex syntax for a IIS URL Rewrite rule where a URL does NOT contain a string?URL 不包含字符串的 IIS URL 重写规则的正确正则表达式语法是什么?
【发布时间】:2015-12-19 05:37:03
【问题描述】:

我正在尝试为 IIS 8.0 URL 模块编写正则表达式,其中:

(网址 /en URL 以 /en/ 开头) 该 URL NOT 包含 switchLanguage=true)

我的 web.config 中有以下规则...

<rule name="Remove Default Language" stopProcessing="true">
    <match url="(^en$|^en/(.*)$)(?&lt;!switchLanguage=true(.*))" />
    <conditions>
    </conditions>
    <action type="Redirect" url="{R:1}" />
</rule>

...但这会导致抛出 500.52 错误,并显示匹配语法无效的消息。

任何帮助将不胜感激。

【问题讨论】:

    标签: regex iis url-rewrite-module


    【解决方案1】:

    我想通了。似乎是我试图使用 RegEx 脚本完成太多工作。

    以下规则有效——注意否定条件。

    <rule name="Remove Default Language" stopProcessing="true">
        <match url="^en$|^en/(.*)$" />
        <conditions>
            <add input="{QUERY_STRING}" pattern="switchlanguage=true" negate="true" ignoreCase="true" />
        </conditions>
        <action type="Redirect" url="{R:1}" />
    </rule>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多