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