Converting iRules to NetScaler Policies - Rewrite HTTP Redirect Response From 301 To 302

Converting iRules to NetScaler Policies - Rewrite HTTP Redirect Response From 301 To 302

book

Article ID: CTX206822

calendar_today

Updated On:

Description

Use Case

Rewrite HTTP responses with HTTP status code 301 which is for Permanent Redirect to 302 which is used for Temporary Redirect.

F5 iRules

# To redirect to the same location, same protocol:
			when HTTP_RESPONSE {
			if { [HTTP::status] == "301" } {
			# respond with 302 using original Location value HTTP::respond 302 Location [HTTP::header Location]
			}
			}
			# To redirect to the same location but change protocol from HTTP to HTTPS:
			when HTTP_RESPONSE {
			if { [HTTP::status] == "301" } {
			# respond with 302 using original Location value
			HTTP::respond 302 Location [string map { http:// https:// } [HTTP::header Location]]
			}
			}

Source:  https://devcentral.f5.com/codeshare/rewrite-http-redirect-301-to-302

NetScaler Solution

add rewrite action 301_302 replace HTTP.RES.FULL_HEADER.AFTER_STR(" ").BEFORE_STR("\r\n") '"302 Found"'

add rewrite policy 301_302_pol 'HTTP.RES.STATUS.EQ(301)' 301_302_act

Bind Rewrite policy to specific VSERVER or to Global rewrite bind point on response flow. Here we are parsing the HTTP response from backend to find out the Status code “301” and then rewrite it with the action to “302 Found”.

 

Issue/Introduction

Converting iRules to NetScaler Policies - Rewrite HTTP Redirect Response From 301 To 302.

Additional Information