• View Communities
    • Citrix Developer Network
      The place for unfiltered straight talk on Citrix products. Blogs, code downloads, best practices, APIs, and more can all be found here.
    • Citrix Ready Community Verified
      Does it work with Citrix? Application compatibility questions are a thing of the past with the new Citrix Community Verified site.
    • Blogs
      Learn the latest from the Citrix employees who are building application delivery infrastructure technologies.
    • Blogosphere
      The Citrix Blogosphere is a window into the thousands of conversations taking place about Citrix and Application Delivery.
  •  Sign In
NetScaler Developer Network

Chaining Rewrite Policies and Actions

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

Tags

rewrite rewrite Delete
appexpert appexpert Delete
pe pe Delete
policy policy Delete
action action Delete
policies policies Delete
actions actions Delete
code code Delete
set-cookie set-cookie Delete
etag etag Delete
pragma pragma Delete
max-age max-age Delete
cache-control cache-control Delete
priority priority Delete
goto goto Delete
pattern pattern Delete
rewrite chain rewrite chain Delete
chaining rewrite chaining rewrite Delete
policy engine policy engine Delete
policy label policy label Delete
how to how to Delete
Enter tags to add to this page:
Please wait 
Looking for a tag? Just start typing.
Related Links