Forum Discussion

pgsmith_120398's avatar
pgsmith_120398
Icon for Nimbostratus rankNimbostratus
Jan 14, 2014

Sorry page redirect

Im trying to set up an iRule that will redirect traffic to an IIS server when there are no active pool members. I have the basics working. However the sorry page will only display properly the first time if there is a uri. If the user refreshes the page or tries a different uri they get a 404.

when HTTP_REQUEST {
    if { [active_members [LB::server pool]] < 1} {
        HTTP::uri "/"
        pool /ESI/solr.erp-pool
    }
}

How would i configure this irule to apply every time the user refreshes the page or hits the url again?

8 Replies

    • pgsmith_120398's avatar
      pgsmith_120398
      Icon for Nimbostratus rankNimbostratus
      Is there an alternate method? This sorry rule will be used on hundreds of websites some of which can not use the one connect profile. I tried redirecting to the host instead of removing the uri with no luck. I can redirect to another URL that points to a sorry page VS but I would prefer the user doesn't see a URL host change. HTTP::redirect "http://[HTTP::host]"
  • Yes there is a workaround. Try this;-

    when CLIENT_ACCEPTED {
        set def_pl [LB::server pool]
    }
    when HTTP_REQUEST {
        if {![active_members $def_pl]} {
            HTTP::uri "/"
            pool /ESI/solr.erp-pool
        } else {
            pool $def_pl
        }
    }
    
    • pgsmith_120398's avatar
      pgsmith_120398
      Icon for Nimbostratus rankNimbostratus
      I'm sorry if this is a stupid question but could you explain how this rule differs from my original. It looks like it does the same thing in a different manner.
  • Sorry I was running out the door to lunch when I posted that. Now I have food I can explain;-

     

    Without oneconnect enabled, each time HTTP_REQUEST is enabled, the current pool will be the last one selected on the same TCP connection, previous HTTP_REQUEST. So using your iRule, let's say your pool members are down and you invoke the /ESI/solr.erp-pool pool. The next time HTTP_REQUEST is executed, the pool returned by [LB::server pool] will be /ESI/solr.erp-pool. When you check it for active members, it will have them, so you send the request to it. Unfortunately you are sending a path other than "?" so you get a 404 .

     

    My rule simple saves the default pool so that it is the one you always check for active members. In addition if the current pool does have active members it will explicitly select the default pool - just in case your default pool goes down and then come back up.

     

    I hope that makes sense.

     

    • pgsmith_120398's avatar
      pgsmith_120398
      Icon for Nimbostratus rankNimbostratus
      Perfect. that code works great with one exception which i started with. That rips out every uri including the /images and /css portions of the sorry pages. My sites are set up with an index.html file at the root with an images and css folder. The sorry pages will all have the same exact structure so excluding the uri's /images and /css (if those are actually present in the request) would be acceptable. If those words are not present there are only about 10 images and 1 css file that i wouldn't mind creating a DG for and doing a look up in the rule. Is this possible? I haven't been able to get it to work. when CLIENT_ACCEPTED { set def_pl [LB::server pool] } when HTTP_REQUEST { if { [active_members [LB::server pool]] < 1} { pool /ESI/solr.erp-pool if {![HTTP::uri] contains "images"} { HTTP::uri "/" } else { pool $def_pl } } }
    • pgsmith_120398's avatar
      pgsmith_120398
      Icon for Nimbostratus rankNimbostratus
      i realized after i posted that irule that it was formatted incorrectly. This is what i have and its still not working, i just get a "page cant be displayed". when CLIENT_ACCEPTED { set def_pl [LB::server pool] } when HTTP_REQUEST { if { [active_members [LB::server pool]] < 1} { if {![HTTP::uri] contains "uf"} { HTTP::uri "/" } pool /ESI/solr.erp-pool } else { pool $def_pl } } i would think that by adding the "if {![HTTP::uri] contains "uf"} { HTTP::uri "/"}" line that would mean that any uri except one that includes "uf" will be removed. I may not be able to do this, but i would like to accomplish this on the F5 as its the simplest single point i can set this up at.
  • Hi pgsmith,

    There best way is to methodically approach this. You need to be able to debug, so use the developer tools in Chrome/Firefox or HTTPWatch (IE/Firefox) or some other tool, so you can see which request are not being responded to.

    Next a suggestion, you said you don't want to see a URL Host change, but how about a URL Path change? You could redirect to http://[HTTP::host]/sorry

    when CLIENT_ACCEPTED {
        set def_pl [LB::server pool]
    }
    
    when HTTP_REQUEST {
        if {[HTTP::path] eq "/sorry" || [HTTP::header "Referrer"] ends_with "/sorry"} {
            pool /ESI/solr.erp-pool
        } elseif { [active_members [LB::server pool]] < 1} {
            HTTP::redirect "http:://[HTTP::host]/sorry"
            return
        } else {
            pool $def_pl
        }
    }