繁体   English   中英

如何使用IIS重写模块重定向除少数请求以外的所有请求

[英]How to redirect all requests excepts few ones, using IIS Rewrite Module

我试图在具体域上仅允许几个URL,所有其他请求应重定向到404 Not Found。 我知道如何将具体的URL重定向到404,但是我需要对此进行反转。 我该如何写这样的规则,应该使用什么条件? 是否存在规则语法not match问题?

所以,我目前正在使用什么:

<rule name="Deny some request" enabled="true" stopProcessing="true">
      <match url="^(.*)$" />
      <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
        <add input="{HTTP_HOST}" pattern="(.*)(\.domain_regexp_here.*)$" negate="true" />
        <add input="{REQUEST_URI}" pattern="(.*)(somename)$" />
      </conditions>
      <action type="Redirect" url="/Home/PageNotFound" appendQueryString="false" />
    </rule>

但是由于这样的规则现在太多了,所以我什至会错过其中的一些。这就是为什么我想简化一点,以便允许一些URL,并将所有其他的重定向到NotFound。

好的,我找到了答案。 关键条件是negate="true"

<rule name="RequestBlockingRule1" stopProcessing="true">
                <match url=".*" />
                <conditions>
                    <add input="{URL}" pattern="url path" negate="true" />
                </conditions>
                <action type="CustomResponse" statusCode="404" statusReason="File or directory not found." statusDescription="The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable." />
            </rule>

如果网址允许多个网址-添加更多条件,然后将logicalGrouping="MatchAll"放入conditions节点。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM