In this example we going to rewrite HTTP redirect on server response.
Assume that client is trying to connect to website which has been moved to different location and as a result Apache or IIS is sending HTTP response code 301 (Permanent Redirect) but we want to change it to code 302 (Temporary Redirect). There may be number of reasons to do it. For example Internet search engines behaviour will vary depends on HTTP code returned.
iRule below will search for HTTP status code 301 in packets returning from the web server to the client and replace it with code 302.
iRule code
when HTTP_RESPONSE { if { [HTTP::status] == "301" } { HTTP::respond 302 Location [HTTP::header Location] } }
Note: You can also use this iRule to do opposite action and rewrite 302 with 301 or any other code. Simply change code numeric values.