How to Configure Rewrite Policy on NetScaler to Replace Text in HTML Body

How to Configure Rewrite Policy on NetScaler to Replace Text in HTML Body

book

Article ID: CTX203510

calendar_today

Updated On:

Description

This article describes how to configure rewrite policy on NetScaler to replace text in the body of HTML page.


Instructions

In this example, udskiftmig is replaced with with morten and (replaceme)|(endnuentest) is replaced with bjarneregex.

The following is the rewrite policy on NetScaler which is used to replace text in the body of HTML page.
add rewrite action RWAC_Http_to_https replace_all "http.res.body(1000000)" "\"morten\"" -pattern udskiftmig
add rewrite action RWAC_Ourwiki_links_to_FQDN replace_all "HTTP.RES.BODY(1000000)" "\"bjarneregex\"" -search "regex(re~(replaceme)|(endnuentest)~)"
add rewrite policy RW_POL_Http_to_Https_links TRUE RWAC_Http_to_https NOREWRITE
add rewrite policy RW_POL_Ourwiki_links TRUE RWAC_Ourwiki_links_to_FQDN NOREWRITE
add lb vserver lbvs_debian_http HTTP 172.16.4.18 80 -persistenceType NONE -cltTimeout 180
add server srv_debian x.x.x.x
add service svc_debian_http srv_debian HTTP 80 -gslb NONE -maxClient 0 -maxReq 0 -cip DISABLED -usip NO -useproxyport YES -sp ON -cltTimeout 180 -svrTimeout 360 -CKA NO -TCPB NO -CMP NO
bind lb vserver lbvs_debian_http svc_debian_http
bind lb vserver lbvs_debian_http -policyName RW_POL_Http_to_Https_links -priority 100 -gotoPriorityExpression NEXT -type RESPONSE
bind lb vserver lbvs_debian_http -policyName RW_POL_Ourwiki_links -priority 110 -gotoPriorityExpression END -type RESPONSE

Note: If the compression is enabled on the backend then there is a chance that the preceding commands will not work as expected. In this case create a request rewrite policy to delete the accept encoding header.

Environment

The above mentioned sample code is provided to you as is with no representations, warranties or conditions of any kind. You may use, modify and distribute it at your own risk. CITRIX DISCLAIMS ALL WARRANTIES WHATSOEVER, EXPRESS, IMPLIED, WRITTEN, ORAL OR STATUTORY, INCLUDING WITHOUT LIMITATION WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NONINFRINGEMENT. Without limiting the generality of the foregoing, you acknowledge and agree that (a) the sample code may exhibit errors, design flaws or other problems, possibly resulting in loss of data or damage to property; (b) it may not be possible to make the sample code fully functional; and (c) Citrix may, without notice or liability to you, cease to make available the current version and/or any future versions of the sample code. In no event should the code be used to support ultra-hazardous activities, including but not limited to life support or blasting activities. NEITHER CITRIX NOR ITS AFFILIATES OR AGENTS WILL BE LIABLE, UNDER BREACH OF CONTRACT OR ANY OTHER THEORY OF LIABILITY, FOR ANY DAMAGES WHATSOEVER ARISING FROM USE OF THE SAMPLE CODE, INCLUDING WITHOUT LIMITATION DIRECT, SPECIAL, INCIDENTAL, PUNITIVE, CONSEQUENTIAL OR OTHER DAMAGES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Although the copyright in the code belongs to Citrix, any distribution of the sample code should include only your own standard copyright attribution, and not that of Citrix. You agree to indemnify and defend Citrix against any and all claims arising from your use, modification or distribution of the sample code.

Issue/Introduction

This article describes how to configure rewrite policy on NetScaler to replace text in the body of HTML page.