Forum Discussion
custom error page based on /URI
Hi I have a iRule on our application server that is catching all 4xx and 5xx error responses and responds with a custom response using the below iRule. We have some application that has inbuilt error page set up and we don't want to put the iRule on those apps. So what I am looking for is to implement the existing iRule based on /URI
when HTTP_REQUEST {
set http_request [HTTP::request]
set appvar [HTTP::cookie JSESSIONID]
set http_request_time [clock clicks -milliseconds]
set LogString "Client [IP::client_addr]:[TCP::client_port] -> [HTTP::host][HTTP::uri]"
set delay 4
}
when HTTP_RESPONSE {
if { ([HTTP::status] starts_with "4") || ([HTTP::status] starts_with "5")} {
HTTP::respond 200 content " MySite\
Oops! Something went wrong. Please try again.\
Sorry for this inconvenience. " "Content-Type" "text/html"
log local0. "$LogString (response) - pool info: [LB::server] - status: [HTTP::status] (request/response delta: [expr {[clock clicks -milliseconds] - $http_request_time}] ms)"
log local0. "Session ID was $appvar"
}
}
Thanks - Rony
1 Reply
- Kevin_Stewart
Employee
Without rebuilding your entire iRule, the logic for such a requirements might look like this:
when HTTP_REQUEST { if { [string tolower [HTTP::uri]] starts_with "/uri" } { set noerror 1 } } when HTTP_RESPONSE { if { ( ( [HTTP::status] starts_with "4" ) or ( [HTTP::status] starts_with "5" ) ) and not ( [info exists noerror] ) } { HTTP::respond 200 content "..." } }This will set a variable in the HTTP_REQUEST event if a specific URI is requested, which will be visible in the corresponding HTTP_RESPONSE event. If users might flip between applications in a single connection, you can optionally add the following to the bottom of the HTTP_RESPONSE event to clear the variable between requests if it exists:
if { [info exists noerror] } { unset noerror }
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* 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