Forum Discussion
how to ignore internal 404 response and only activate a irule on a full page 404 response ( such as css, image etc. )
Hi,
Just for a background I have a irule to catch 4xx and 5xx response and do a generic html response and redirect to maintenance/homepage.
All was working good until some pages had internal resource 404 such as ( css, images, etc ) .. On these internal 404 the irule seemed to trigger thus breaking the page. How can I deal with this situation? Is there any way to only trigger the irule on a full page 404 not for the internal resources ?
Many thanks, - Rony
3 Replies
- Mohamed_Lrhazi
Altocumulus
Yes, there is... Just identify the requests that represent full page as opposed to those that represent page component :)
Maybe "full page" is only these:
/ /index.html /index.php /products /products/ /products/index.htm
- Kevin_Stewart
Employee
You could go either I think, but you'd more or less have to define all page objects or all non-page objects, or at least object extensions. Here's an example that defines non-page objects from a data group.
when HTTP_REQUEST { if { [class match [string tolower [HTTP::uri]] ends_with objectlist] } { set do_not_err 1 } } when HTTP_RESPONSE { if { [info exists do_not_err] } { unset do_not_err return } elseif { ( [HTTP::status] starts_with "40" ) or ( [HTTP::status] starts_with "50" ) } { HTTP::respond 200 content "Broken" } }where objectlist is a string-based data group that contains the lowercased extensions of known object types that you might encounter on a page. Example.
jpg gif png js css - IheartF5_45022
Nacreous
If you page 'breaks' when you get a redirect to a maintenance page for an includes-type object, then I suspect that it will 'break' when you get a 404. However to answer your actual question this should work;-
when RULE_INIT { List of well known 'page' extensions set static::l_ext [list "" "do" "htm" "html" "jsp" "asp" "aspx" "wml" "xhtml" "json" "cfm"] } when HTTP_REQUEST { Save variable for possible later use in HTTP_RESPONSE set request [HTTP::uri] } when HTTP_RESPONSE { if {[HTTP::status] == 404 && [lsearch $static::l_ext [string tolower [getfield [URI::basename $request] "." 2]]] != -1 } { HTTP::respond 302 noserver Location "http://mycomapny.com/sorry_404.htm" return }
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