Forum Discussion

gdoyle's avatar
gdoyle
Icon for Cirrostratus rankCirrostratus
Dec 02, 2018

If/Else Redirect Irule Question.

I have an irule that redirects to different pools based on the URI (I have posted it several times). I'm having an issue in that the redirect appears to be looping due to the website making calls to multiple URIs and most of them are not defined (these are things like favicons and page borders, etc...). So instead of going to the redirect the URI should be pointing them to the irule is running again and sending them to a default pool.

How do I get this to stop looping? Is there a way I can stop the irule from processing once it matches and completes an "if/then" condition?

I have included the irule below. Sections with Pool1 and Pool2 are working without issue.

Thanks.

when HTTP_REQUEST {
    log local0. "Making URI lowercase."
    switch -glob [string tolower [HTTP::uri]] {
      "/abc/xyz" -
      "/abc/xyz/" -
      "/" { 
    log local0. "Redirecting based on /abc/xyz."
        HTTP::respond 301 "Location" "https://myplace.com/abc/xyz/myplace" 
       }
      "/redirect*" { 
     log local0. "Redirecting based on redirect"

 
 This next section states that if there are more than 0 pool members are active in the Pool1_pool 
 then the user is redirected there, else they are presented a Maintenance Page.

          if { [active_members Pool1_pool] > 0 } {
            log local0. "Sending to Pool1_pool."
              pool Pool1_pool 
          } else {
            log local0. "Sending to MX Page for Pool1_pool."
              HTTP::respond 503 content [ifile get "/external/MaintenancePage_ifile"] noserver "Content-Type" "text/html" "Cache-Control" "no-cache, must-revalidate"
              return
          }
      }
      "*/hrp/*" { 
        log local0. "Redirecting based on hrp."

 
 This next section states that if there are more than 0 pool members are active in the Pool2_pool 
 then the user is redirected there, else they are presented a Maintenance Page.

          if { [active_members Pool2_pool] > 0 } {
            log local0. "Sending to Pool2_pool."
              pool Pool2_pool 
          } else {
            log local0. "Sending to MX Page for the Pool2_pool."
              HTTP::respond 503 content [ifile get "/external/MaintenancePage_ifile"] noserver "Content-Type" "text/html" "Cache-Control" "no-cache, must-revalidate"
              return
          }
       }
      default { 
        log local0. "Redirecting based on default."

 
 This next section states that if there are more than 0 pool members are active in the Pool3_pool 
 then the user is redirected there, else they are presented a Maintenance Page.

          if { [active_members Pool3_pool] > 0 } {
            log local0. "Sending to the Pool3_pool."
              pool Pool3_pool 
          } else {
            log local0. "Sending to MX Page for the Pool3_pool."
              HTTP::respond 503 content [ifile get "/external/MaintenancePage_ifile"] noserver "Content-Type" "text/html" "Cache-Control" "no-cache, must-revalidate"
              return
          }
      }
    }

 This next section inserts an HttpsIndicatorHeader value of True to prevent Websphere redirect errors.

    log local0. "Inserting HttpsIndicatorHeader Value"
    HTTP::header insert HttpsIndicatorHeader True
}

1 Reply