Forum Discussion
LyonsG_85618
Cirrostratus
Jan 13, 2015Rewrite HTTP response when error code received
Hi
I need to capture 500 errors and when I receive them return a preformated error page.
This page will sit on a different domain (where the digital publishing team can update it quickly) and there...
Arie
Altostratus
Jan 16, 2015Here's another approach that doesn't require HTTP::uri. The rule may or may not work as-is since I pulled out environment-specific stuff and inserted your new pool and host. However, it should still provide a template.
when HTTP_RESPONSE {
if { [HTTP::status] equals 403 || [HTTP::status] equals 404 } {
Retrieve the not-found page if the HTTP status is 403, 404
Note: Retrieving the page is a valid request, which means that the server will respond with a 200 OK.
This necessitates that we collect the payload so we can later construct a custom response with
the proper HTTP response code (404) but with the payload (HTML) from this request.
if { ![info exists retry] } {
set retry 1
HTTP::header replace Host "new.domain.com"
pool /TEST/POOL_FOR_NEW_DOMAIN
HTTP::retry "GET /error/not-found/ HTTP/1.1\r\nHost:$requested_host\r\n\r\n"
}
}
if { [info exists is404] } {
if { [HTTP::status] equals 200 } {
store the payload of the not-found page if the HTTP status is 200
(this means that the error page was found on the file system)
HTTP::collect [HTTP::header Content-Length]
} else {
No error page was found in the folder. Construct a generic error page
and send it to the client.
log local0.debug "is404 true, but there's no error page on the file system. ([HTTP::status])"
HTTP::respond 404 content {
}
}
}
}
when HTTP_RESPONSE_DATA {
Construct the response with the payload of the not-found page that we collected earlier and
with the HTTP Response Code "404".
HTTP::respond 404 content [HTTP::payload] "Content-Type" "text/html"
}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
