Forum Discussion
John_Lennon_457
Nimbostratus
Mar 22, 2010Redirection to HTML error page if no pool selected
I'm new at using a LTM. I'm using ProxyPass V10 - http://devcentral.f5.com/wiki/default.aspx/iRules/ProxyPassV10.html - I wrote a script to convert the almost 1,000 rules from our Reverse Proxy to this format (with some cleanup too) and it's working fine. The issue I'm having is with the handling of mistakes (mistyped URLs or similar) for which I don't have a solution.
I tried to add a 2nd iRule where I do some redirections but the 404 isn't always a good test as the error the user gets is a connection reset (as no data is sent by the web servers if the URL is invalid).
when HTTP_REQUEST {
switch -glob [HTTP::uri] {
"/" { HTTP::uri {/home} }
"/mashups*" { HTTP::uri {/home/html/product.jsp?p=mashups} }
"/images*" { HTTP::uri {/images} }
"/error.html" { HTTP::uri {/error_gh.html} }
"/down.html" { HTTP::uri {/down.html} }
"/catalog*" { HTTP::uri {/plugins/plugincatalog} }
"/MastHead/*" { HTTP::uri {/images} }
}
}
when HTTP_RESPONSE {
if { [HTTP::status] contains "404"} {
HTTP::redirect "https://www.mysite.com/error.html"
}
}
I about 20 or so Pools selected with the ProxyPass iRule, what I'd like to accomplish is:
- be redirected to an error.html page when no pool is dynamically selected (I don't have a default pool) regardless of the URL typed
- be redirected to an error.html page when the user types a wrong URL and the web server doesn't return any response
Ideally I'd like to handle these cases in the iRule above, not in the ProxyPass one.
Thanks for your help and hints.
- hoolio
Cirrostratus
Hi John,- be redirected to an error.html page when no pool is dynamically selected (I don't have a default pool) regardless of the URL typed
- be redirected to an error.html page when the user types a wrong URL and the web server doesn't return any response
- John_Lennon_457
Nimbostratus
Hi Aaron,when HTTP_REQUEST priority 501 { if { [LB::server pool] eq $default_pool } { set myURI "[HTTP::uri]" HTTP::redirect "https://www.mysite.com/error.html" HTTP::uri {/error_gh.html} log local0.error "Redirecting user IP: [IP::client_addr] to /error.html, URI requested: $myURI $default_pool" } }
- hoolio
Cirrostratus
If you're rewriting the request using HTTP::uri, the URI would be updated and then sent to the default pool. If the default pool doesn't include valid IP:ports, then the request would fail. I thought you wanted to send an HTTP redirect. In that case, the client should get the redirect. - John_Lennon_457
Nimbostratus
I had to change from redirection to change the URI as with redirection I get this: - John_Lennon_457
Nimbostratus
BTW, the default pool has valid IP:ports. - hoolio
Cirrostratus
Ah, I forgot that the ProxyPass iRule would be redirecting some requests. You could set a variable at the beginning of HTTP_REQUEST (set redirected 0) and then set it to 1 for the two HTTP::redirects. You could then check if $redirect==0 before trying to redirect in the second iRule. - John_Lennon_457
Nimbostratus
I'm sorry but it doesn't seem to work quite yet: - hoolio
Cirrostratus
I don't think I was very clear in the last post... I was trying to suggest that you modify the ProxyPass iRule to add a "redirected" variable to track whether the ProxyPass iRule had attempted a redirect. So you could add 'set redirected 0' at the beginning of the ProxyPass HTTP_REQUEST event, add 'set redirected 1' before each HTTP::redirect command in the ProxyPass iRule and then only use HTTP::redirect in the second iRule if '$redirected==0'. - John_Lennon_457
Nimbostratus
Your posting was very clear but it introduced the issue I showed. I've rewritten my rules since and I'll try a different approach, I'm sure you'll see a post soon :-)
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