Forum Discussion
AlexDeMarco
Nimbostratus
Sep 25, 2012How 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
- Mohamed_Lrhazi
Altocumulus
There should be a "string fucntion" called "equals", instead of using "starts_with" - Mohamed_Lrhazi
Altocumulus
Oh, it not a string function, but an "operator" : https://devcentral.f5.com/wiki/iRules.Operators.ashx - What_Lies_Bene1
Cirrostratus
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. - What_Lies_Bene1
Cirrostratus
Or perhaps you could match on /ca/? - AlexDeMarco
Nimbostratus
I probably should use a regex to only match on exactly the phrases I want.
Thanks for all the comments... - Michael_Yates
Nimbostratus
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.
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects