Rewrite

The rewrite feature is a very useful feature when Citrix NetScaler is used to publish HTTP/SSL or TCP information. This feature can be used for request or response traffic. Rewrite is very useful for hiding/removing configurations, appending the default page, custom HTTP errors, hiding HTTP headers, and so on.

The working of the rewrite feature

The rewrite feature requires a rule and an action to perform the required tasks. The rule is used to identify whether the rule needs to be applied. The configured action will perform the actual action—what we like to rewrite. It's possible to bind multiple rewrite policies on every bind point. Based on the priority, we can define what needs to be applied first if the rule matches the request.

The bind point could be at a global level or defined for a specific Citrix NetScaler load balancing or content switching virtual server.

The rewrite feature also has some default rewrites installed, and these can't be deleted.

The policies from the rewrite feature are followed according to these steps:

  1. First, Citrix NetScaler will check for global policies.
  2. After the global policies, Citrix NetScaler will verify the policies at the bind point. If there are multiple policies, then Citrix NetScaler will evaluate the policies based on the configured priority. The lowest priority will be evaluated first. This policy will be evaluated. If the policy matches, Citrix NetScaler will add the rule to the list of performing actions.
  3. After all the evaluated policies are walked through, the listed actions will be conducted.

The GoTo expression

While adding the rewrite policy to the bind point, there is the GoTo expression, which can be filled in. The default is the END function. The options available are as follows:

  • END: Evaluation after the policy will be ended. This means that no policy will be evaluated after this one.
  • NEXT: The next available policy will be evaluated, if it exists.
  • USE_INVOCATION_RESULT: GoTo END or NEXT based on the results of the invocation list.
    The GoTo expression

The preceding diagram describes the flowchart of the rewrite feature.

Rewrite actions

Citrix NetScaler has a lot of actions available for performing actions. The most commonly used action will be explained as follows:

Rewrite action type

Expression to choose target location

Argument

INSERT_HTTP_HEADER: Inserts the HTTP header that we like to insert.

The HTTP header that we like to insert.

The expression that describes the contents of the HTTP header that needs to be inserted.

INSERT_BEFORE: Inserts a new string before the target location.

The expression that contains information on where the action needs to be evaluated.

The text that needs to be added before the target location.

INSERT_AFTER: Inserts a new string after the target location.

The expression that contains information on where the action needs to be evaluated.

The text that needs to be added after the target location.

REPLACE: Replaces the designated string with a different string.

The expression that contains information on where the action needs to be evaluated.

The text that needs to be replaced by the target location expression.

DELETE: Deletes the designated information.

A string expression that describes what needs to be deleted.

 

DELETE_HTTP_HEADER: Deletes the designated HTTP header.

The name of the HTTP header that we want to delete.

 

CORRUPT_HTTP_HEADER: Replaces the name of the HTTP header with a corrupted name. If this type is used, the receiver can't recognize this HTTP header.

The name of the HTTP header that we don't want visible on the receiver side.

 

REPLACE_HTTP_RES: Replaces the HTTP response.

The matching expression that needs to be sent back. This will be an HTTP response.

 

REPLACE_ALL: Replaces all the designated strings with a different string.

The expression that contains information on where the action needs to be evaluated.

All of the text that needs to be replaced by the target location expression.

DELETE_ALL: Delete every occurrence that matches the target location.

A string expression that describes what needs to be deleted.

 

INSERT_AFTER_ALL: Inserts a new string after the target location. This will be used to insert for all the matching target locations rather than just the first match.

The expression that contains information on where the action needs to be evaluated.

The text that needs to be added after the target location.

INSERT_BEFORE_ALL: Inserts a new string before the target location.

The expression that contains information on where the action needs to be evaluated.

The text that needs to be added before the target location.

Configuring a rewrite policy

Go to AppExpert | Rewrite | Actions and click on Add. Fill in the correct information based on the following explanation:

  • Name: This will be the name where the rewrite actions will be named to.
  • Type: Select the rewrite type that you want to perform. The most commonly used types have been described previously.

    Depending on the type, there will be an extra field that needs to be filled in.

  • Comments: Fill in comments if necessary.

Now the action is done, and we need to create a policy.

Go to AppExpert | Rewrite | Policies and click on Add. Fill in the correct information based on the explanation given here:

  • Name: This will be the name where the rewrite actions will be named to
  • Action: There are different options here, as follows:
    • Insert: The rewrite action that we created earlier. All rewrite actions will be visible.
    • NOREWRITE: The request or response will not be rewritten.
    • RESET: The connection will be aborted at the TCP level.
    • DROP: The message will be dropped.
  • Log action: When the rewrite policy matches, it's possible to log the action to an SNMP server or the syslog of Citrix NetScaler
  • Undefined-Result Action: When an error occurs, for some reason, Citrix NetScaler will perform the selected action
  • Expression: Configure the expression that Citrix NetScaler needs to check whether the action needs to be processed
  • Comments: Fill in comments if necessary

After these steps, we can bind the policy to the global level or a specific Citrix NetScaler virtual server.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset