Forum Discussion

George_32239's avatar
George_32239
Icon for Nimbostratus rankNimbostratus
Oct 27, 2009

Multiple comparisons in an iRule

Hello All,

 

 

I need a rule that will look at a hostname the [HTTP::host] and also looke at part of the URI, the [HTTP:uri] bit.

 

 

If both conditions are the same I need to send the request to a certain pool if both sets do not match need to send them to another pool.

 

 

I don't know if an ANDIF statement exists.

 

 

Apologies in advance, our firm has not sent us on any training courses and am struggling with this

 

 

Any help greatly appreciated

 

 

Thanks,

 

 

George
  • I think I figured it out using the following;

     

     

    when HTTP_REQUEST {

     

    if { [HTTP::host] eq "somehost.com" && [HTTP::uri] contains "somestring"} {

     

    pool some_pool }

     

    else

     

    {pool some_other_pool}

     

    }

     

     

    I am now going to try the string tolower bit

     

     

    Thanks
  • hoolio's avatar
    hoolio
    Icon for Cirrostratus rankCirrostratus
    Hi George,

    There are quite a few examples in the forums and the iRules wiki of iRules which check the host (retrieved using HTTP::host Click here) and the URI (retrieved using HTTP::uri Click here).

    Here is one example of checking the host and URI to select corresponding pools:

     
     when HTTP_REQUEST { 
      
         This event is triggered when LTM parses the HTTP request headers 
      
         Check requested host using lower case 
        if {[string tolower [HTTP::host]] eq "subdomain.example.com"}{ 
      
            Check the requested URI 
           if {[HTTP::uri] starts_with "/some_uri"}{ 
               pool some_pool 
           } else { 
               pool other_pool 
           } 
        } else { 
           pool some_other_pool 
        } 
     } 
     

    Aaron
  • Hi Aaron,

     

     

    Many thanks for your reply. I should have an environment I can test on tomorrow.

     

     

    George