LB_FAILED not always triggered when all members disabled
Hi there
I'm on a mission to create a generic iRule in order to serve sorry-pages from fallback hosts.
A few criterias that was needed:
1. Strip the subdomain.
2. Preserve the customer URI while rewriting it in the internal request (so that the real page will be served when the user keeps hitting F5).
Potential imporovement:
3. Cache the response
So, I got a good thing going and it looked like it was working as expected. If I go to a random link while there's no available members it serves the page, BUT if I alter the link in the location field of the browser and hit enter it does not serve the fallback page but a 404 instead.
To summarize:
1. Going to http://fallbacktest.test.com/ajsdjasjdjasdjasjd
2. Fallback page is served.
3. Change http://fallbacktest.test.com/ajsdjasjdjasdjasjd to http://fallbacktest.test.com/jkjkjkjkjkjkjkjkjkjkjk
4. A 404 is served.
After some troubleshooting I realized that the reason for this was that the LB_FAILED event was not triggered.
Any ideas of why?
Here's the rule:
when LB_FAILED {
A generic iRule for redirecting users to sorry pages
Create an array separating the host header by .
set hostlist [split [string tolower [HTTP::host]] "."]
Capture the last to items of the array turning ie. subdomain.domain.com to domain.com
set domain "[lindex $hostlist end-1].[lindex $hostlist end]"
Save the length of the host header
set length [llength $hostlist]
set uri [HTTP::uri]
If the length of the hostlist is greater than 1 the value has the correct format.
if { $length > 1 } {
Replace the host header with the string stored in $domain
HTTP::header replace host $domain
Replacing the URI if needed
if { !($uri eq "/default.htm" || $uri starts_with "/img/") } {
HTTP::uri "/index.html"
} else {
log local0. "Correct uri"
}
Reselect pool to the Sorry pool
LB::reselect pool /Site/SorryPages_Pool-80
} else {
HTTP::respond 200 content "Invalid host header format."
}
}
Kind regards,
Patrik