Forum Discussion
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!
4 Replies
- Kevin_Stewart
Employee
when HTTP_REQUEST { if { ( [string tolower [HTTP::uri]] contains "upload" ) and ( [string tolower [HTTP::uri]] contains "images" ) } { pool SERVER1 } else { pool SOME_OTHER_POOl } } - dyobbs_25515
Nimbostratus
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?
- Kevin_Stewart
Employee
The switch command itself is more comparable with an "if/else if". There's no "and" option.
- mimlo_61970
Cumulonimbus
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_POOLThen create a datagroup (named uri_Datagroup in the above example) of type string and put all of your URIs in it.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* 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
