For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

mimino_136976's avatar
mimino_136976
Icon for Nimbostratus rankNimbostratus
Nov 04, 2013

iRule redirect when 404

Hi, I'm using BIG-IP (trial version). In internal VLAN I have 2 back-ends servers. I need some rule that will redirect to the next back-end server if first response code 404. Also I tried to use the following rule:

 

when HTTP_RESPONSE {
if { [HTTP::status] contains "404"} {
HTTP::redirect "http://www.google.com/"
}
}

but it doesn't work. Could you, please, help me with given issue? Could you, please, help me?

 

4 Replies

  • If you have other code in your HTTP_RESPONSE you need to have 'return' after the redirect ie;-

     

    if { [HTTP::status] eq "404"} {
        HTTP::redirect "http://www.google.com/"
        return
    }

    Otherwise bad stuff happens ie. doesn't work.

     

  • If I may add, I don't think the original description intends for an explicit redirect. As I understood it, Mimino simply wants to "fail over" to another server in the pool if the selected server returns a 404. If that's the case, something like this should work.

    when CLIENT_ACCEPTED {
         set reqcount to the total number of servers in assigned pool
        set reqcount [active_members [LB::server pool]]
    }
    when HTTP_REQUEST {
         save the client request
        set req [HTTP::request]
    }
    when HTTP_RESPONSE {
        if { [HTTP::status] equals 404 } {
             if request count is greater than 0, decrement variable and retry request
            if { $reqcount > 0 } {
                incr reqcount -1
                HTTP::retry $req
            } else {
                 all servers have been tried, so send a maintenance page
                HTTP::respond 200 content "Oops! You've asked for something we don't have."
            }
        }
    }
    

    If a 404 response is detected, another server will be chosen automatically. This iRule will then retry the original request for each member of the pool. If all servers return 404, then a static error page will be displayed.

  • Thanks for all the help. I found root cause in my configuration Virtual Server. Also interesting solution was seen by me for my approach by this link http://shaun.net/2012/05/f5-big-ip-health-checks-and-http-errors/