This article describes how to use URL Transformation on NetScaler to change the destination path of a GET request based on the User-Agent.
Before starting with the URL Transformation configuration it would be beneficial to get an HTTP Header trace to confirm the User-Agents for the client requests. The following two User-Agents are taken from a client using Firefox, version 3.5.8, and Microsoft Internet Explorer, version 7.0. The URL Transformation policy can be configured to match on any expression in the User-Agent header value field.
Firefox UA:
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.8) Gecko/20100202 Firefox/3.5.8 GTB6 (.NET CLR 3.5.30729)
Internet Explorer UA:
User-Agent: Mozilla/4.0 (compatible; GoogleToolbar 6.4.1321.1732; Windows XP 5.1; MSIE 7.0.5730.11)
All of the following steps should be added through the NetScaler CLI, however, they can also be added through the GUI using the Rewrite section > URL Transformation sub-section.
Create the necessary profiles to contain the actions using the following commands:
add transform profile ua_url-trans_IE.pro
add transform profile ua_url-trans_Firefox_pro
Create a URL Transformation action to adjust the URL in its entirety using the following commands. The protocol, hostname, path, and query can all be manually adjusted. The reqUrlFrom section supports Regex and has the ability to create variables ($1) based on word groups. The $1 - $9 variables can be used in the reqUrlInto section.
add transform action ua_url-trans_Firefox_act ua_url-trans_Firefox_pro 100
add transform action ua_url-trans_IE_act ua_url-trans_IE.pro 100
set transform action ua_url-trans_Firefox_act -priority 100 -reqUrlFrom "http://10.54.80.224" -reqUrlInto "http://10.54.80.224/Firefox"
set transform action ua_url-trans_IE_act -priority 100 -reqUrlFrom "http://10.54.80.224" -reqUrlInto "http://10.54.80.224/IE"
Configure policies to match the destination IP address of the virtual server and the User-Agent header. The regular expression match of the User-Agent header will be case insensitive. The IP address of the VIP is added because of the global binding of URL transformation.
add transform policy ua_url-trans_Firefox_pol "http.REQ.HOSTNAME.EQ(\"10.54.80.224\") && HTTP.REQ.HEADER(\"User-Agent\").SET_TEXT_MODE(IGNORECASE).REGEX_MATCH(re/Firefox/) " ua_url-trans_Firefox_pro
add transform policy ua_url-trans_IE_pol "http.REQ.HOSTNAME.EQ(\"10.54.80.224\") && HTTP.REQ.HEADER(\"User-Agent\").SET_TEXT_MODE(IGNORECASE).REGEX_MATCH(re/MSIE/) " ua_url-trans_IE.pro
Globally bind the URL Transformation policies in priority order 20 and 30 using the following commands. When using global bind points you should make the policy expression as specific as possible to prevent matching unintended client requests.
bind transform global ua_url-trans_Firefox_pol 20
bind transform global ua_url-trans_IE_pol 30
The following packet capture screen shot shows a client GET request, using Firefox, to / being adjusted to /Firefox/ for the NetScaler request to the back end server. The second GET request from the client was made using Internet Explorer as the web browser. This resulted in the GET / request being manipulated to GET /IE/ for the back end request.
Environment:
Client IP - 10.54.67.214
Virtual Server - 10.54.80.224
SNIP - 10.54.80.33
Server - 10.54.80.24