Forum Discussion

dyobbs_25515's avatar
dyobbs_25515
Icon for Nimbostratus rankNimbostratus
Jul 22, 2015

iRule to match 2 or more strings in the URI?

I have this requirement to match 2 uris in the same request. i have this iRule:

 

when HTTP_REQUEST { switch -glob [HTTP::host][HTTP::uri] { "/upload" - " images " { pool SERVER1 } } }

 

The iRule above match "upload" or "images" then go to the pool.

 

What if I wanted to check both "upload" and "images" on the same request, and if match you go to pool SERVER1? what will be the iRule format? Any change on the " - " syntax?

 

thanks!

 

  • I would recommend you use a datagroup to store all of the possible values and then search against it.

    when HTTP_REQUEST {
        if { [ class match [HTTP::uri] contains uri_Datagroup ] } {
            pool SERVER1
        } else {
            pool SOME_OTHER_POOL
    

    Then create a datagroup (named uri_Datagroup in the above example) of type string and put all of your URIs in it.

  • The switch command itself is more comparable with an "if/else if". There's no "and" option.

     

  • Thanks Kevin, any chance that we can use the "switch command", the strings that i need to match are about a hundred :)

     

    I’m wondering if there’s a change in the “ – “ syntax to check match both strings, as this works as an OR, what can we use to make it AND statement?

     

  • when HTTP_REQUEST {    
       if { ( [string tolower [HTTP::uri]] contains "upload" ) and ( [string tolower [HTTP::uri]] contains "images" ) } {       
          pool SERVER1
       } else {       
          pool SOME_OTHER_POOl
       }
    }