2016-10-19 39 views
0

我想只允許幾個具體域上的URL,所有其他請求應重定向到404未找到。 我知道如何將一個具體的URL重定向到404,但我需要像這樣的反轉。我如何編寫這樣的規則,我應該使用什麼條件?規則語法中是否有類似not match如何重定向除了少數幾個請求,使用IIS重寫模塊

所以,我現在使用的是:

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

但由於現在有太多的這樣的規則,讓我甚至可以錯過其中的一部分,這就是爲什麼我想簡化了一下,以便我允許一些網址,並將所有其他網址重定向到NotFound。

回答

0

好的,我找到了答案。關鍵是在條件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節點。