2015-08-14 15 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

很好,谢谢。 –