1. 程式人生 > >Netscaler URL/Cookie domain Transformation 轉換

Netscaler URL/Cookie domain Transformation 轉換

cond rec 正則表達式 run top transform iter db4 證明

Netscaler URL/Cookie domain Transformation 轉換
我們經常會碰到很多URL或cookie改寫的需求,在netscaler10.1版本以前只能通過比較復雜的標準rewrite策略來做,不但費時而且還容易出錯。後續的版本特意把比較這類操作頻繁但需求又不復雜的操作從rewrite中摘出來,形成 transformation模塊。可以做轉換的對象包括request方向和response方向的URL(註意是hostname+URI都可以改,不只是路徑),Cookie的domain,復合正則表達式可以用的非常靈活(如果感覺正則不太會寫,可以參考《Netscaler數據索引String Map與Pattern Set的 》來方便枚舉不算太多的參數)總之Netscaler的設計就是在滿足穩定性和功能性的前提下盡量讓大家的操作簡單。

在Rewrite策略下先建立Profile,
技術分享圖片

建立Profile後填寫需要轉換內容的表達式
技術分享圖片
轉換的對象可以是Request、Responde和Cookie Domain,對於前兩者可以是URI也可以是完整的URL。
技術分享圖片

然後建立 URL Transformation Policy
技術分享圖片
技術分享圖片
將此策略綁定到需要的VIP上
技術分享圖片
技術分享圖片
觀察效果:
轉換前
技術分享圖片
轉換後。因為我的服務器上沒有/111這個路徑,所以看到報錯證明轉換生效。
技術分享圖片

官方文檔

How to Change Destination Hostname of HTTP GET Request Using URL Transformation Feature
CTX128091 Created onMay 07, 2014 Updated onMay 07, 2014

1 found this helpful
Article Topic : Configuration
See Applicable Products
Objective
This article provides information on how to change the Destination Hostname of an HTTP GET Request using the URL Transformation feature.

Instructions
To change the destination hostname of an HTTP GET request using the URL Transformation feature of a NetScaler appliance, complete the following procedure:

Run the following command from the command line interface of the appliance to create a URL Transformation profile:

add transform profile prof_url_change

Run the following command to create a URL ransformation action:

add transform action act_url_change prof_url_change 100

Run the following command to configure a URL Transformation action:

set transform action act_url_change -priority 100 -reqUrlFrom "http://one.example.co.uk/(.)/(.)/" -reqUrlInto "http://$1.one.example.local/$2/" -resUrlFrom "http://(.*).one.example.local/(.*)" -resUrlInto “http://one.example.co.uk/$1/$2”

In the preceding command, the reqUrlFrom section is regex-compliant. Therefore, you can create variables, such as $1, based on word groups. You can use $1 to $5 variables for the reqUrlInto parameter.
Note: The $1 variable refers to the first (.), the $2 variable refers to the second (.), and / is a delimiter.

Run the following command to configure the URL Transformation policy:

add transform policy pol_url_change "HTTP.REQ.URL.PATH.GET(1).EQ(\"firstpath\") && HTTP.REQ.HOSTNAME.EQ(\"one.example.co.uk\")" prof_url_change

Run the following command to bind the policy globally to the appliance:

bind transform global pol_url_change 10

After configuring the appliance with the preceding configuration, if you try to access the http://one.example.co.uk/firstpath/secondpath/test.html URL, the appliance sends the http://firstpath.one.example.co.uk/secondpath/test.html URL to the backend server.

Note: In this article, URL is transformed using the first element of the path. However, you can extend this to the other elements of the URL.

來源: <http://support.citrix.com/article/CTX128091>

Netscaler URL/Cookie domain Transformation 轉換