Forum Discussion
natethegreat_23
Nimbostratus
Jul 25, 2017iRule OR statement in URI
In my working iRule for the ASM, I am looking for a specific URI with the statement:
if { [HTTP::uri] starts_with "/abc/zyx/type1/text" }
{ "do action"
}
Now I would like to do the same action for URIs that are exactly the same besides directory type1 now has type1-7. I think that the following code should work:
if { [[HTTP::uri] starts_with "/abc/zyx/type1/text"] || [[HTTP::uri] starts_with "/abc/zyx/type2/text"] || [[HTTP::uri] starts_with "/abc/zyx/type3/text"] || ......... }
{ "do action"
}
But that gets out of hand with 7 different types and needed ORs. Is there a way to make a simpler code with somehow only needing to type the full URI once? Something that looks like:
if { [HTTP::uri] starts_with "/abc/zyx/[type1-7]/text" }
{ "do action"
}
Or am I stuck with copying the whole URI out 7 times? Thank you!
1 Reply
- Stanislas_Piro2
Cumulonimbus
Hi,
you can use switch:
switch -glob -- [HTTP::path] { "/abc/zyx/type[1-7]/text*" { "do action" } }
or
switch -glob -- [HTTP::path] { "/abc/zyx/type1/text*" - "/abc/zyx/type2/text*" - "/abc/zyx/type3/text*" - "/abc/zyx/type4/text*" - "/abc/zyx/type5/text*" - "/abc/zyx/type6/text*" - "/abc/zyx/type7/text*" { "do action" } }
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