Forum Discussion
Arie
Jan 16, 2015Altostratus
Here'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"
}