Rule to automatically "follow" an internal redirect?

Hi, I’m new to iRules. I see the example of detecting a redirect and rewriting the Location header:

but is it possible to instead follow the redirect within BigIP (an internal redirect?), so that the HTTP 301/302 does not go back to the browser?

E.g., browser requests www.example.com/foo/bar.html. BigIP load balances this request to either internal1.example.com or internal2.example.com. But, internal1 might respond with a 301 with “Location: http://internal2.example.com/foo/bar.html”. The browser cannot see internal1 / internal2.

Thanks, Jamshid

Hi Jamshid,

Sure.. there’s an example on the HTTP::retry wiki page you could adapt:

http://devcentral.f5.com/wiki/default.aspx/iRules/http__retry
 One can save a WAN round trip by following a redirect at the LTM and responding to the 
 original client request with the result of the redirect
when HTTP_REQUEST {

    Save the host header value
   set host [HTTP::host]
}
when HTTP_RESPONSE {

    Check if response is a redirect based on the status code
   if { [HTTP::is_redirect] } {

       Now generate a GET request to the new location
      HTTP::retry "GET [HTTP::header location] HTTP/1.1\r\nHost: $host\r\n\r\n"
   }
}

Aaron

Here is an example to capture a 301 and 302 and redirect them.

First one is to redirect to a different website.

Second one is to redirect back to the base page. You could also redirect them to a pretty error page, etc.

when HTTP_RESPONSE {
     if { [HTTP::status] == "301" } {
         HTTP::redirect "http://www.website.com/"
     }
     elseif { [HTTP::status] == "302" } {
         HTTP::redirect "http://[HTTP::host]/index.html"
     }
}