Forum Discussion

computerli's avatar
computerli
Icon for Altostratus rankAltostratus
Aug 01, 2013

Execute two If condition in one iRule -- sorry page

I am new to iRule and need help in creating a sorry page

 

Here is condition

 

I have two pool english and french. When the nodes in the English pool are offline then redirect to URL (example google.com). When the nodes in French pool are offline then redirect to URL (example yahoo.com). I don’t want to redirect both

 

 

Here is iRule

 

 

when HTTP_REQUEST {

 

if {[active_members english] == 0} {

 

HTTP::redirect "http://google.com"

 

}

 

if {[active_members french] == 0 } {

 

HTTP::redirect "http://yahoo.com/"

 

}

 

}

 

 

Here is the problem

 

If the English pool is offline then the request get redirected to google.com, but it also redirect the request to French to google.com.

 

Same is true other way around. If French pool is offline then it is redirected to yahoo.com, but the English pool also get redirected to yahoo.com

 

I want to redirect only if the condition is true for which-ever pool. E.g English or French.

 

 

Please help

 

3 Replies

  • Quick question. How are you directing user requests to the English or French pools? The Accept-Language header? A URI?
  • I think you need to perform the active_members conditional within the scope of the requested language. Something like this perhaps:

    
    when HTTP_REQUEST {
    switch [string tolower [HTTP::header Accept-Language]] {
    "en" {
    if { [active_members english] == 0 } {
    HTTP::redirect "http://google.com"
    } else {
    pool english
    }
    }
    "fr" {
    if { [active_members french] == 0 } {
    HTTP::redirect "http://yahoo.com"
    } else { 
    pool french
    }
    }
    default {
     do something else...
    }
    }
    }