How to Rewrite Server HTTP Response Codes to Redirect Clients to a Different Page

How to Rewrite Server HTTP Response Codes to Redirect Clients to a Different Page

book

Article ID: CTX237393

calendar_today

Updated On:

Description

At times, you might want to redirect a client to a different page based upon the server's response. For example, you could redirect a user to a custom page instead of the standard 404 error message when the Web site is not available. You can use the HTTP Rewrite feature of the NetScaler appliance to redirect the client requests to a customized Web page.


Instructions

Redirecting the Client Requests to a Custom Page when the Backend Server returns the 404 Response Code

To redirect the client requests to a custom page when the backend server returns the 404 response code, complete the following procedure:

  • Connect to the NetScaler appliance by using an SSH utility, such as PuTTY.
  • From the command line interface of the appliance, run the following command to create a rewrite action:
    add rewrite action sample_rewrite_action replace_http_res "\"HTTP/1.1 302 Temporary Redirect\nLocation: http://<Custom_Error_Page_Link> \n\n\""
      • Run the following command to create a rewrite policy:
        add rewrite policy sample_rewrite_policy 'HTTP.RES.STATUS.EQ(404)' sample_rewrite_action
          • Run the following command to bind the policy globally:
            bind rewrite global sample_rewrite_policy 1
            OR:
            Bind this directly to a Vserver instead of globally like this:
            bind lb vserver LB_VServer_Name -policyName sample_rewrite_policy -priority 100 -type RESPONSE

              Note: In the preceding commands, the 302 Temporarily Redirect response code is used to redirect the client request to the customized page when the server returns a 404.
              Note: Ensure that you have enabled the HTTP Rewrite feature of the NetScaler appliance.