Forum Discussion
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
- Kevin_Stewart
Employee
When you say it doesn't work, do you mean it successfully redirects to Google but that's not what you want? Take a look at the HTTP::retry wiki page for a good example:
https://devcentral.f5.com/wiki/iRules.HTTP__retry.ashx
- IheartF5_45022
Nacreous
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.
- Kevin_Stewart
Employee
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.
- mimino_136976
Nimbostratus
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/
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com