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 ...
hoolio
Cirrostratus
Apr 04, 2008The 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.
Do you know why the application responds with a 500 when requesting the an image referenced by the root page of the site? That might be the first thing to address.
If you wanted to handle this better in an iRule, you might create a list of page types (like .do or /) and then only redirect requests to pages (as opposed to images) if they generate a 4xx or 5xx response from the web app. You could rewrite all other responses 4xx/5xx responses to 200 with no content.
Also, once you enable blocking on your ASM security policy, ASM will automatically take the blocking action for all 5xx responses (except 502).
Can you give this updated rule a try?
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"
}
}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
