Forum Discussion
mimino_136976
Nimbostratus
Nov 04, 2013iRule 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 ...
Kevin_Stewart
Employee
Nov 05, 2013If 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.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects