Aug 21

How to rewrite HTTP redirect 301 to 302 using iRules on F5 LTM

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

  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.

Follow me!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>