【问题标题】:IIS rewrite rule for processing all URLs except given用于处理除给定之外的所有 URL 的 IIS 重写规则
【发布时间】:2013-09-18 14:14:49
【问题描述】:

这里是一些要处理的 URL 的 IIS 重写规则:

    <rule name="rule" stopProcessing="true">
      <match url="^(word|world|hero|about)[/]?$" />
      <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
      </conditions>
      <action type="Rewrite" url="/info.aspx?id={R:1}" />
    </rule>

如何创建相反的规则?例如,我想处理除“/special”、“/escape”之外的所有 URL。这个:

    <rule name="rule" stopProcessing="true">
      <match url="^(?!(special)&amp;?!(escape))[/]?$" />
      <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
      </conditions>
      <action type="Rewrite" url="/info.aspx?id={R:1}" />
    </rule>

不起作用。 “/special” 和 “/escape” URL 会按应有的方式处理,但其他 URL 会给我 404 页。

【问题讨论】:

    标签: iis url-rewriting


    【解决方案1】:

    在这种情况下,您必须使用negate 属性。

    您的规则将变为:

    <rule name="rule" stopProcessing="true">
      <match url="^(special|escape)/?$" negate="true" />
      <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
      </conditions>
      <action type="Rewrite" url="/info.aspx?id={R:1}" />
    </rule>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-01
      • 2018-08-29
      • 1970-01-01
      • 2014-10-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多