Example 12: Configure rewrite policy to replace a part of the URL directory

The following section describes the procedure to configure a rewrite policy on a NetScaler appliance to replace a part of the URL directory.

Consider a user who wants to replace the first directory of the URL. For example, the user types the URL www.example.com/aaa/bbb/ccc/ddd, and the first directory (aaa) is replaced by www.example.com/zzz/bbb/ccc/ddd.

You can follow the subsequent steps to replace a part of URL directory using NetScaler appliance.

Perform the following by using the GUI

  1. Create an action of type REPLACE.

    Rewrite replace

  2. Create a Rewrite policy and specify the action created in step 1.

    Rewrite policy

  3. The following image is a sample GET request screen from where the policy is tested.

    Rewrite replace

Perform the following by using the CLI

  1. Create Rewrite action.

    add rewrite action action-url replace "HTTP.REQ.URL.PATH.GET(1)" "\"zzz\""

  2. Create Rewrite policy.

    add rewrite policy policy-url true action-url

  3. Bind the Rewrite policy to the load balancing virtual server.

    bind lb vserver "<VSERVER_NAME>" -policyName <REWRITE_POLICY_NAME> -priority <PRIORITY> -type REWRITE

Note

If you want to replace the second directory in the URL, then you must create the action as HTTP.REQ.URL.PATH.GET(2). For further replacement of directory, you must follow the same step.

Example 12: Configure rewrite policy to replace a part of the URL directory