This article contains a case study in chaining multiple Rewrite actions.
Summary
The Rewrite feature, unlike other NetScaler features, allows multiple policies to match, and multiple actions to be performed on, a single request or response. Each rewrite action is performed on the unmodified request or response header, however, meaning that chained rewrite actions are "unaware" of each other. Because of this, you must be careful to perform only one rewrite action per header, or you risk unexpected and usually unwanted results.
This article shows how to perform a series of rewrite actions on a single request that meets certain criteria. The example below performs four actions on each request for a GIF image file that collectively strip out unnecessary headers, and add a single cache control header.
First, you add your Rewrite actions. The action below, named act_del_Set-Cookie, removes the Set-Cookie header from the request:
> add rewrite action "act_del_Set-Cookie" delete_http_header "Set-Cookie"
The name of this action contains a hyphen, and must therefore be enclosed in double quotes.
The action below, named act_del_ETag, removes the ETag header:
> add rewrite action act_del_ETag delete_http_header ETag
The action below, named act_del_Pragma, removes the Pragma header, which is normally used to prevent caching of dynamic responses:
> add rewrite action act_del_Pragma delete_http_header Pragma
The action below, named act_ins_Cache-Control, inserts a Cache-Control header that sets the maximum age of the cached image file, telling the browser when to retrieve a fresh copy of the image file.
> add rewrite action "act_ins_Cache-Control" insert_http_header "Cache-Control" "\"max-age=2592001;log\""
Next, you must add a Rewrite policy for each of the Rewrite actions you created above:
> add rewrite policy "pol_del_SET-COOKIE" "HTTP.REQ.URL.SUFFIX.CONTAINS(\"gif\") && HTTP.RES.HEADER(\"SET-COOKIE\").EXISTS " "act_del_Set-Cookie"
> add rewrite policy pol_del_ETAG "HTTP.RES.HEADER(\"ETag\").EXISTS " act_del_ETag
> add rewrite policy pol_del_Pragma "HTTP.RES.HEADER(\"Pragma\").EXISTS " act_del_Pragma
> add rewrite policy "pol_ins_Cache-Control" TRUE "act_ins_Cache-Control"
This step links each Rewrite action to the appropriate Rewrite policy. The first Rewrite policy tests the request to see whether the request is for a GIF file, and ontains an unnecessary Set-Cookie header. If the request matches this policy, the entire policy chain is invoked. Otherwise, the entire policy chain is skipped.
Next, you add a Rewrite policy label that you will use to link the four Rewrite policies together:
> add rewrite policylabel pol_res http_res
This step provides the name that you will use to link each policy to the policy chain.
Next, you bind the Rewrite policy label to all but the first of your Rewrite policies, assigning a numeric priority and a link to the priority of the next Rewrite policy to each:
> bind rewrite policylabel pol_res "pol_del_ETAG" 1 2
> bind rewrite policylabel pol_res pol_del_Pragma 2 3
> bind rewrite policylabel pol_res "pol_ins_Cache-Control" 3 END
This step creates the policy chain, linking each policy to the policy label and setting the order in which each policy is evaluated.
Finally, you bind your load balancing vserver VIP to your first Rewrite policy, invoking the policy label for your chain, as shown below:
> bind lb vserver vip -policyName "pol_del_SET-COOKIE" -priority 1 -gotoPriorityExpression 2 -type RESPONSE -invoke policylabel pol_res
This step binds your Rewrite policy chain the vserver VIP, putting it into effect.
More Information