我知道我可以使用{HTTP_COOKIE}规则条件部分中的变量基于cookie的值重写URL .此规则获取一个名为ServerProxy的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>
Run Code Online (Sandbox Code Playgroud)
如果ServerProxycookie不存在或未设置,我想将流量定向到名为的身份验证服务器authenticate.app.如何编写可以执行此操作的重写规则?
试试这个:
<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>
Run Code Online (Sandbox Code Playgroud)
请注意,*已更改为+确保cookie不为空.否定简单地翻转条件,因此使其为空或不存在.
| 归档时间: |
|
| 查看次数: |
635 次 |
| 最近记录: |