Summary
This article describes how to extract tokens from incoming requests.
Background
In the Token hash load balancing method, you must extract the token from the incoming request. If the token is part of either a URL or URL query, it is pretty straight forward, but sometimes the token is in the URL and sometimes it is in the URL query.
Procedure
Starting from NetScaler version 9.0, the load balancing component supports the PI Rule Language (PIRL) to achieve this. It supports compound expressions using PIXL.
Example:
If the URL looks like: http://vip/function/<token>/<user>, you would want to be able to select <token> as the data value to hash from.
Alternately, the token could part of the URL query like: http://vip/function?id=<token>
To capture the token in both cases, use the ALT operator (supported only in version 9.0 and later) as follows:
add lb vserver abcd HTTP 1.1.1.1 80 -persistenceType NONE -lbMethod TOKEN -rule "HTTP.REQ.URL.QUERY.VALUE(\"id\") ALT HTTP.REQ.URL.PATH.GET(1)"