Forum Discussion
Don_22992
Nimbostratus
Apr 02, 2008stubborn 4xx/5xx Error Handler
I am sure this is simple....
I have the following iRule to redirect 4xx & 5xx errors to a page on a backend server. It works great - once I have sucessfully connected to the site once! What am I missing?
when HTTP_REQUEST {
set myhost [HTTP::host]
}
when HTTP_RESPONSE {
if { ([HTTP::status] starts_with "4")} {
HTTP::redirect https://$myhost/images/errors/err_4xx.htm
} elseif { ([HTTP::status] starts_with "5")} {
HTTP::redirect https://$myhost/images/errors/err_5xx.htm
} else {
}
}
- hoolio
Cirrostratus
Can you clarify this? If the pool member responds with a 4xx or 5xx status, the first response still gets through to the client but any subsequent response is redirected? Is that what you mean?when HTTP_REQUEST { set myhost [HTTP::host] } when HTTP_RESPONSE { log local0. "[IP::client_addr]:[TCP::client_port]: Request $myhost generated response status: [HTTP::status]" if { ([HTTP::status] starts_with "4")} { log local0. "[IP::client_addr]:[TCP::client_port]: Redirecting to 4xx.htm" HTTP::redirect https://$myhost/images/errors/err_4xx.htm } elseif { ([HTTP::status] starts_with "5")} { log local0. "[IP::client_addr]:[TCP::client_port]: Redirecting to 5xx.htm" HTTP::redirect https://$myhost/images/errors/err_5xx.htm } else { log local0. "[IP::client_addr]:[TCP::client_port]: Doing nothing" } }
- hoolio
Cirrostratus
The rule looks like it's working as it's written. If the server responds with a 4xx or 5xx response, the response is rewritten to a 302 redirect. However, I don't think you actually want to redirect all 4xx and 5xx responses. The browser won't follow the redirect if the redirect is in response to a request for an image. I don't think even if it were possible, that you'd want to redirect the previous request to a page if a single image referenced on the page wasn't found.when RULE_INIT { set ::page_suffixes [list \ .do \ / \ ] } when HTTP_REQUEST { set myhost [HTTP::host] set mypath [HTTP::path] } when HTTP_RESPONSE { log local0. "[IP::client_addr]:[TCP::client_port]: Request $myhost generated response status: [HTTP::status]" if { ([HTTP::status] starts_with "4")} { if { $mypath ends_with $::page_suffixes }{ log local0. "[IP::client_addr]:[TCP::client_port]: request to $mypath generated a [HTTP::status], redirecting to 4xx.htm" HTTP::redirect https://$myhost/images/errors/err_4xx.htm } else { log local0. "[IP::client_addr]:[TCP::client_port]: request to $mypath generated a [HTTP::status], responding with a 200" HTTP::respond 200 } } elseif { ([HTTP::status] starts_with "5")} { if { $mypath ends_with $::page_suffixes }{ log local0. "[IP::client_addr]:[TCP::client_port]: request to $mypath generated a [HTTP::status], redirecting to 5xx.htm" HTTP::redirect https://$myhost/images/errors/err_5xx.htm } else { log local0. "[IP::client_addr]:[TCP::client_port]: request to $mypath generated a [HTTP::status], responding with a 200" HTTP::respond 200 } } else { log local0. "[IP::client_addr]:[TCP::client_port]: Doing nothing" } }
- Don_22992
Nimbostratus
Aaron, - hoolio
Cirrostratus
Hi Don, - Don_22992
Nimbostratus
Aaron, - hoolio
Cirrostratus
In previous versions of BIG-IP ASM, you'd need to disable ASM when sending a response from an iRule (Click here). I didn't think that would be necessary in 9.4.2+ with the plugin architecture. Can you open a case with F5 Support asking them to investigate this? If you want to try one more thing, you could explicitly disable the ASM plugin when sending a redirect:when HTTP_REQUEST { set myhost [HTTP::host] } when HTTP_RESPONSE { Initialise a variable to track whether we're redirecting this request set redirect 0 log local0. "[IP::client_addr]:[TCP::client_port]: Request $myhost generated response status: [HTTP::status]" if { ([HTTP::status] starts_with "4")} { log local0. "[IP::client_addr]:[TCP::client_port]: Redirecting to 4xx.htm" HTTP::redirect https://$myhost/images/errors/err_4xx.htm set redirect 1 } elseif { ([HTTP::status] starts_with "5")} { log local0. "[IP::client_addr]:[TCP::client_port]: Redirecting to 5xx.htm" HTTP::redirect https://$myhost/images/errors/err_5xx.htm set redirect 1 } else { log local0. "[IP::client_addr]:[TCP::client_port]: Doing nothing" } } when HTTP_CLASS_SELECTED { If the request is being redirected, disable ASM if {$redirect}{ Enable ASM by default PLUGIN::disable ASM } else { Enable ASM by default PLUGIN::enable ASM } }
- Don_22992
Nimbostratus
Aaron,
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