Forum Discussion

Fotios_30046's avatar
Fotios_30046
Icon for Nimbostratus rankNimbostratus
Feb 26, 2010

Combine Two Rules Into One

I have two rules that perform the same function but on different domains. If a subfolder of /products is found use a different pool, otherwise use the default. My question is, can these be combined into a single rule and if so, where do I check for the domain? Before the switch or after?

 

 

The rules in question.

 

 

Rule 1 - Domain 1

 

 

when HTTP_REQUEST {

 

switch -glob [HTTP::uri] {

 

"/products*" { pool Altruik-Furniture}

 

default { pool Furniture-Production-Pool-HTTP }

 

}

 

}

 

 

Rule 1 - Domain 2

 

 

when HTTP_REQUEST {

 

switch -glob [HTTP::uri] {

 

"/products*" { pool Altruik-CarpetOne}

 

default { pool CarpetOne-Production-Pool }

 

}

 

}

3 Replies

  • You can do it several ways and the deciding factor is which makes more sense to you. Performance should be equivalent. Either of these should work

    when HTTP_REQUEST { 
       switch [HTTP::host] { 
         "www.domain1.com" { 
           switch -glob [HTTP::uri] { 
             "/products*" { pool Altruik-Furniture } 
             default { pool Furniture-Production-Pool-HTTP } 
           } 
         } 
         "www.domain2.com" { 
           switch -glob [HTTP::uri] { 
             "/products*" { pool Altruik-CarpetOne} 
             default { pool CarpetOne-Production-Pool } 
           } 
         } 
       } 
     }

    One question though. Is there a reason why you don't have the default pool setup for the virtuals in the virtual configuration? If you set the default for the domain1 virtual to Furniture-Production-Pool-HTTP and the default pool set for the domain2 virtual to CarpetOne-Production-Pool, then you could have an iRule that looks something like this

    when HTTP_REQUEST [ 
       if { [HTTP::uri] starts_with "/products" } { 
         switch [HTTP::host] { 
           "www.domain1.com" { pool Altruik-Furniture } 
           "www.domain2.com" { pool Altruik-CarpetOne } 
         } 
       } 
     }

    Lots of options, just pick one that works for you!

    -Joe

  • I like the last option, but just be sure to use a OneConnect profile if you're not specifying a pool for all cases. Else, you could save the name of the VIP's default pool and specify it as a default:

      
      when CLIENT_ACCEPTED {  
        
          Save the name of the VIP's default pool  
         set default_pool [LB::server pool]  
      }  
      when HTTP_REQUEST [   
         if { [HTTP::uri] starts_with "/products" } {   
            switch [string tolower [HTTP::host]] {   
               "www.domain1.com" { pool Altruik-Furniture; return  }  
               "www.domain2.com" { pool Altruik-CarpetOne; return }  
            }   
         }  
          If we're still in the rule, there wasn't a match  
          so explicitly use the default pool  
         pool $default_pool  
      }  
      

    If you don't specify the pool in all cases and don't use a OneConnect profile, multiple requests on the same TCP connection can go to the wrong pool. See this post for details:

    http://devcentral.f5.com/Default.aspx?tabid=53&view=topic&postid=1167449&ptarget=1167577

    Aaron
  • Aaron,

     

     

    Each VS does have a default pool. This Altruik pool is an appliance that handles specific requests. However, when linking back to the main site, the requests fail without the default entry in the switch.

     

     

    -Fotios