when HTTP_REQUEST {
if { [HTTP::uri] contains "pagenotfound.html" } {
event disable all
}
}
when HTTP_RESPONSE {
if { [HTTP::status] == "404" or [HTTP::status] == "500" }{
HTTP::redirect "http://www.yournamehere.com/error/pagenotfound.html"
}
}
I am hoping it is possible to modify this to keep the original URL but send back the pagenotfound.html content, similar to a passthrough directive on apache. Is this at all possible?
It would be relatively simple to do this if you wanted to respond from the rule with the HTML content for pagenotfound.html. You could do this following the maintenance page codeshare example:
I am having a hard time understanding how to do this without any redirect. We are not under an LB_FAILED scenario and just want to keep the original URI, but if the web server is returning a 404, send back the contents of the error page without redirection. Here is a non-working code example of what I am trying to accomplish:
when HTTP_REQUEST {
if { [HTTP::uri] contains "404.jsp" } {
event disable all
}
}
when HTTP_RESPONSE {
if { [HTTP::status] == "404" or [HTTP::status] == "500" }{
HTTP::uri "/404.jsp" This doesn't work in HTTP_RESPONSE
LB::reselect pool error_pool This doesn't work in HTTP_RESPONSE
}
}
If you want to reselect a member of a new pool, you’d need to use HTTP::retry from HTTP_RESPONSE. You can then specify a new pool in HTTP_REQUEST if the failure condition is true for that request. I’ve done a quick search for this specific scenario, but I don’t see any identical posts. There are quite a few similar posts though in this forum. If you searching and get stuck, reply with what you’ve tested.
I think I’ve found a solution, but I wanted to see if there are other ideas on how to do it, or if this seems at all silly:
when CLIENT_ACCEPTED {
set retries 0
}
when HTTP_REQUEST {
set request [HTTP::request]
}
when LB_SELECTED {
if { $retries >= 1 } {
LB::reselect pool server_404
}
}
when HTTP_RESPONSE {
if { [HTTP::status] == "404" or [HTTP::status] == "500" } {
incr retries
HTTP::retry $request
}
}
I can then use apache (which is the only member in the server_404 pool) to do a pass through redirect. This is needed to allow the browser to retain the original URI and not display /error/404.html:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/error/404.html
RewriteRule ^/.*$ /error/404.html [PT,L]
Thoughts? Is there a way to eliminate the Apache rewrite altogether?