2015-08-14 26 views
6

我知道我可以使用規則的條件部分中的{HTTP_COOKIE}變量基於cookie中的值重寫url。該規則抓取一個名爲ServerProxy的cookie,並對該服務器url進行重寫。使用ARR如果Cookie丟失,您如何重寫url?

<rule name="SendTrafficToServerProxyCookieValue" stopProcessing="true"> 
    <match url="(.*)" /> 
    <action type="Rewrite" url="http://{C:1}/{R:0}" /> 
    <conditions> 
     <add input="{HTTP_COOKIE}" pattern="ServerProxy=(.*)" /> 
    </conditions> 
</rule> 

如果ServerProxy cookie是缺席或取消,我想交通引導到名爲authenticate.app認證服務器。我如何編寫一個重寫規則來做到這一點?

回答

5

試試這個:

<rule name="SendTrafficToServerProxyCookieValue" stopProcessing="true"> 
    <match url="(.*)" /> 
    <action type="Rewrite" url="http://{C:1}/{R:0}" /> 
    <conditions> 
     <add input="{HTTP_COOKIE}" pattern="ServerProxy=(.+)" /> 
    </conditions> 
</rule> 
<rule name="DoAuthRewrite" stopProcessing="true"> 
    <match url="(.*)" /> 
    <action type="Rewrite" url="SOMETHING_ELSE" /> 
    <conditions> 
     <add input="{HTTP_COOKIE}" pattern="ServerProxy=(.+)" negate="true" /> 
    </conditions> 
</rule> 

注意*已更改爲+,以確保Cookie是不是空的。否定只是翻轉條件,因此使其變爲空或不存在。

+0

很好,謝謝。 –