Forum Discussion

AlexDeMarco's avatar
AlexDeMarco
Icon for Nimbostratus rankNimbostratus
Sep 25, 2012

How to narrrow the match

Here is a small snippet of my code:

 

([string tolower [HTTP::uri]] starts_with "/ca") ||

 

 

We have an application where the context is just /ca so this is working fine for it. However, we have a directory called /capital which this irule is also firing on. How can narraw the match so it is only /ca ?

 

thanks!

 

- Alex

 

 

6 Replies

  • There should be a "string fucntion" called "equals", instead of using "starts_with"
  • Oh, it not a string function, but an "operator" : https://devcentral.f5.com/wiki/iRules.Operators.ashx
  • equals probably won't be useful as the /ca is probably only the start of a full URI? If that's the case you could match on /capital prior to the code you've posted and either terminate rule processing there or 'jump over' the /ca check and processing.
  • I probably should use a regex to only match on exactly the phrases I want.

     

     

    Thanks for all the comments...
  • Changing your matching order would probably be your best bet. Regular expressions can get expensive in processing times and efficiency loss.

    I would suggest What Lies Beneath's suggestion. Using a switch statement you can go from the more specific to the generic to prevent things from firing and causing problems.

    You'll will probably need to follow up your pool decisions with a return statement as well to prevent the next event from interfereing with the previous.

    Try something like this:

    
    when HTTP_REQUEST {
    switch -glob [string tolower [HTTP::uri]] {
    "/capitals*" { pool firstpool; return }
    "/capital*" { pool secondpool; return }
    "/caps*" { pool thirdpool; return }
    "/california*" { pool fourthpool; return }
    "/ca*" { pool fifthpool }
    default { pool defaultpool }
    }
    }
    

    Hope this helps.