Forum Discussion

natethegreat_23's avatar
natethegreat_23
Icon for Nimbostratus rankNimbostratus
Jul 25, 2017

iRule 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

  • 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"
        }
    }