什么是适当的正则表达式语法一个IISURL重写规则的URL不包含一个字符串在哪里? - What is the proper regex syntax for a IIS URL Rewrite rule where a URL does NOT contain a string?

- 此内容更新于:2015-12-20
主题:

我想写一个正则表达式的IIS8.0URL模块:(URL/en或URL开始/en/)和URL不包含switchLanguage=true)我在web.config有以下规则……但这将导致500.52错误抛出一个消息,匹配语法是无效的。任何帮助将不胜感激。

原文:

I am trying to write a regex Expression for the IIS 8.0 URL Module where:

(the URL is /en OR the URL starts with /en/) AND the URL does NOT contain switchLanguage=true)

I have the following rule in my 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>

... but this causes a 500.52 error to be thrown with a message that the match syntax is not valid.

Any help would be greatly appreciated.

解决方案:
我想这一点。它似乎,我试图完成太多使用RegEx脚本。以下规则的作品——注意否定的状态。
原文:

I figured this out. It appears to be that I was trying to accomplish too much using the RegEx script.

The following rule works -- note the negate condition.

<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>