Forum Discussion

yves_werniers_1's avatar
yves_werniers_1
Icon for Nimbostratus rankNimbostratus
Sep 08, 2009

pool selection not working

Hello,

 

 

I have an irule attached to a virtual server (with no default pool).

 

In the rule there are some redirects and a pool selection. The pool selection (first elseif statement) is the problem. If I put something else there (like a redirect), it is executed. But the pool selection isn't, and it falls through to the pool selection at the end of the irule.

 

 

Any ideas?

 

 

when HTTP_REQUEST {

 

if {[HTTP::host] == "www.mydomain.be" and [HTTP::uri] equals "/"} {

 

HTTP::respond 301 Location "http://www.mydomain.eu/be/zz/index.jsp"

 

}

 

elseif {[HTTP::host] == "www.mydomain.be"} {

 

pool mydomain_be_pool

 

}

 

elseif {[HTTP::host] == "www.mydomain.nl"} {

 

HTTP::respond 301 Location "http://www.mydomain.eu/nl/zz/index.jsp"

 

}

 

elseif {[HTTP::host] == "www.mydomain.fr"} {

 

HTTP::respond 301 Location "http://www.mydomain.eu/fr/zz/index.jsp"

 

}

 

elseif {[HTTP::host] == "mydomain.fr"} {

 

HTTP::respond 301 Location "http://www.mydomain.eu/fr/zz/index.jsp"

 

}

 

if {[HTTP::host] == "www.mydomain.lu"} {

 

HTTP::respond 301 Location "http://www.mydomain.eu/lu/zz"

 

}

 

elseif {[HTTP::host] == "www.mydomain.eu" and [HTTP::uri] equals "/"} {

 

HTTP::respond 301 Location "http://www.mydomain.eu/zz/index.html"

 

}

 

else {

 

use pool mydomain_eu_pool

 

}

 

}
  • Looking at your logic it appears that that you have the same 2 conditions that match, but only the first will be executed while the second will be ignored For example if someone enters http://www.mydomain.be/ then they will be redirected and and sent to pool mydomain_eu_pool. You need to group them together

      
     .  
     .  
     .  
     when HTTP_REQUEST {  
     if {[HTTP::host] == "www.mydomain.be" and [HTTP::uri] equals "/"} {  
     HTTP::respond 301 Location "http://www.mydomain.eu/be/zz/index.jsp"  
     pool mydomain_be_pool  
     }  
     elseif {[HTTP::host] == "www.mydomain.nl"} {  
     HTTP::respond 301 Location "http://www.mydomain.eu/nl/zz/index.jsp"  
     }   
     .  
     .  
     .  
     

    I also took the liberty of rewriting your entire iRule. This should make things look easier to read. However, since I am not exactly sure what behaviour you wanted I making a lot of assumptions

      
     when HTTP_REQUEST { 
      if [HTTP::uri] eq "/" } { 
      switch -glob [HTTP::host] { 
      "www.mydomain.be" { 
      HTTP::redirect "http://www.mydomain.eu/be/zz/index.jsp" 
      pool mydomain_be_pool 
      } 
      "www.mydomain.nl" { 
      HTTP::redirect "http://www.mydomain.eu/nl/zz/index.jsp" 
      } 
      "www.mydomain.fr" - 
      "mydomain.fr" { 
      HTTP::redirect "http://www.mydomain.eu/fr/zz/index.jsp" 
      } 
      "www.mydomain.lu" { 
      HTTP::redirect "http://www.mydomain.eu/lu/zz" 
      } 
      "www.mydomain.eu" { 
      HTTP::redirect "http://www.mydomain.eu/zz/index.html" 
      } 
      default { 
      pool mydomain_eu_pool 
      } 
      } 
     } 
     } 
     

    Switch commands tend to be easier then writing multiple IF-ELSEIF statements and they tend to execute faster. I also changed from using HTTP::respond 301 to HTTP::redirects

    I hope this helps

    CB
  • Sorry, but it does not work.

     

     

    If I make it

     

     

    when HTTP_REQUEST {

     

    if {[HTTP::host] == "www.mydomain.be" and [HTTP::uri] equals "/"} {

     

    HTTP::respond 301 Location "http://www.mydomain.eu/be/zz/index.jsp"

     

    }

     

    elseif {[HTTP::host] == "www.mydomain.be"} {

     

    pool mydomain_be_pool

     

    }

     

     

    I get sent to the pool at the very end of the irule.

     

    If I make it

     

     

    when HTTP_REQUEST {

     

    if {[HTTP::host] == "www.mydomain.be" and [HTTP::uri] equals "/"} {

     

    HTTP::respond 301 Location "http://www.mydomain.eu/be/zz/index.jsp"

     

    }

     

    elseif {[HTTP::host] == "www.mydomain.be"} {

     

    HTTP::redirect "http://www.anotherdomain.be"

     

    }

     

     

     

    I get redirected to that anotherdomain, so it does evaluate to get in that part of the script, but the pool selection is not doen well?

     

     

    And I use HTTP::respond 301 because I want a "moved permanently" response (for search engine spiders and the like) insteda of a "moved temporarily" that is sent by a HTTP::redirect.

     

     

    yves

     

  • I think the confusion stems from exactly how you want the iRule to behave

     

     

    Again you have 2 conditions that match but only one will be executed

     

     

    For example if you enter http://www.mydomain.be/ you will be redirected http://www.mydomain.eu/be/zz/index.js and sent to pool mydomain_eu_pool

     

    If you enter http://www.mydomain.be/testing then you will be sent to pool mydomain_eu_pool without any redirection.

     

     

    What is the behavior you do want?

     

     

    CB
  • If I enter http://www.mydomain.be/ I want to be redirected to http://www.mydomain.eu/be/zz/index.js and sent to pool mydomain_eu_pool

     

     

    I I enter http://www.mydomain.be/testing, I want to be sent to another pool (mydomain_be_pool).

     

     

    Since a redirect instead of 'pool' works, I assume that I get in that part of the script. So why is that pool selection not done?

     

     

    yves
  • Then I think you need to rewrite it as

      
     when HTTP_REQUEST { 
     if {([HTTP::host] eq "www.mydomain.be") and ([HTTP::uri] eq "/")} { 
             HTTP::respond 301 Location "http://www.mydomain.eu/be/zz/index.jsp" 
     } elseif {[HTTP::host] == "www.mydomain.be"} { 
     pool mydomain_be_pool 
     return 
     } elseif {[HTTP::host] eq "www.mydomain.nl"} { 
     HTTP::respond 301 Location "http://www.mydomain.eu/nl/zz/index.jsp" 
     } elseif {[HTTP::host] eq "www.mydomain.fr"} { 
     HTTP::respond 301 Location "http://www.mydomain.eu/fr/zz/index.jsp" 
     } elseif {[HTTP::host] eq "mydomain.fr"} { 
     HTTP::respond 301 Location "http://www.mydomain.eu/fr/zz/index.jsp" 
     } 
      
     if {[HTTP::host] eq "www.mydomain.lu"} { 
     HTTP::respond 301 Location "http://www.mydomain.eu/lu/zz" 
     } elseif {[HTTP::host] eq "www.mydomain.eu" and [HTTP::uri] eq "/"} { 
     HTTP::respond 301 Location "http://www.mydomain.eu/zz/index.html" 
     } else { 
     pool mydomain_eu_pool 
     } 
     } 
     
  • Modified the iRule to add logging

       
     when HTTP_REQUEST { 
     if {([HTTP::host] eq "www.mydomain.be") and ([HTTP::uri] eq "/")} { 
     HTTP::respond 301 Location "http://www.mydomain.eu/be/zz/index.jsp" 
     log local0.  "This was reached when the url was http://[HTTP::host][HTTP::uri]" 
     } elseif {[HTTP::host] == "www.mydomain.be"} { 
     pool mydomain_be_pool 
     return 
     log local0.  "This was reached when the url was http://[HTTP::host][HTTP::uri]" 
     } elseif {[HTTP::host] eq "www.mydomain.nl"} { 
     HTTP::respond 301 Location "http://www.mydomain.eu/nl/zz/index.jsp" 
     log local0.  "This was reached when the url was http://[HTTP::host][HTTP::uri]" 
     } elseif {[HTTP::host] eq "www.mydomain.fr"} { 
     HTTP::respond 301 Location "http://www.mydomain.eu/fr/zz/index.jsp" 
     log local0.  "This was reached when the url was http://[HTTP::host][HTTP::uri]" 
     } elseif {[HTTP::host] eq "mydomain.fr"} { 
     HTTP::respond 301 Location "http://www.mydomain.eu/fr/zz/index.jsp" 
     log local0.  "This was reached when the url was http://[HTTP::host][HTTP::uri]" 
     } 
      
     if {[HTTP::host] eq "www.mydomain.lu"} { 
     HTTP::respond 301 Location "http://www.mydomain.eu/lu/zz" 
     log local0.  "This was reached when the url was http://[HTTP::host][HTTP::uri]" 
     } elseif {[HTTP::host] eq "www.mydomain.eu" and [HTTP::uri] eq "/"} { 
     HTTP::respond 301 Location "http://www.mydomain.eu/zz/index.html" 
     log local0.  "This was reached when the url was http://[HTTP::host][HTTP::uri]" 
     } else { 
     pool mydomain_eu_pool 
     log local0.  "This was reached when the url was http://[HTTP::host][HTTP::uri]" 
     } 
     } 
     
  • Hi Yves,

    I think you can also re-write this as

      
     when HTTP_REQUEST { 
     if { [HTTP::host] eq "www.mydomain.eu" } { 
        switch -glob [HTTP::uri] { 
          "/" { HTTP::respond 301 Location "http://www.mydomain.eu/zz/index.html"} 
          default { pool mydomain_eu_pool} 
        } 
     } 
     if { [HTTP::host] eq "www.mydomain.be" } { 
        switch -glob [HTTP::uri] { 
          "/" { HTTP::respond 301 Location "http://www.mydomain.eu/be/zz/index.jsp" } 
          default { pool mydomain_be_pool } 
        } 
     } 
     switch -glob [HTTP::host] { 
      "www.mydomain.nl" { HTTP::respond 301 Location "http://www.mydomain.eu/nl/zz/index.jsp"} 
      "www.mydomain.fr" - 
      "mydomain.fr" { HTTP::respond 301 Location "http://www.mydomain.eu/fr/zz/index.jsp } 
      "www.mydomain.lu" { HTTP::respond 301 Location "http://www.mydomain.eu/lu/zz" } 
     } 
     } 
     
  • Colin_Walker_12's avatar
    Colin_Walker_12
    Historic F5 Account
    Very nice work, cmbhatt! 😄

    I think you'd either want to add an else clause as well, to avoid stepping into the additional switch at the end if you've already matched one of the above domains, or just incorporating the above nesting into the switch that you already have based off of the host. Something like:

        
        when HTTP_REQUEST {   
          switch [HTTP::host] {  
            "www.mydomain.eu" {   
              switch [HTTP::uri] {   
                "/" {  HTTP::respond 301 Location "http://www.mydomain.eu/zz/index.html" }   
                default { pool mydomain_eu_pool}   
              }   
            }   
            "www.mydomain.be" {   
              switch [HTTP::uri] {   
                "/" { HTTP::respond 301 Location "http://www.mydomain.eu/be/zz/index.jsp" }   
         default { pool mydomain_be_pool }   
              }   
            }   
            "www.mydomain.nl" { HTTP::respond 301 Location "http://www.mydomain.eu/nl/zz/index.jsp" }   
            "www.mydomain.fr" - 
            "mydomain.fr" { HTTP::respond 301 Location "http://www.mydomain.eu/fr/zz/index.jsp }   
            "www.mydomain.lu" { HTTP::respond 301 Location "http://www.mydomain.eu/lu/zz" }   
          }   
        }  
     

    Colin