Forum Discussion

OttimoMassimo_1's avatar
OttimoMassimo_1
Icon for Nimbostratus rankNimbostratus
Sep 15, 2011

alteration to an existing irule

Hi,

This is definitely a newbie question, so apologies in advance!

I have a context switch within an irule like so:

"/stuff/place*" {

pool my_pool

return

}

I would now like to point /stuff* to the same pool, but in the following manner:

"/stuff*" {

if { some conditions } {

HTTP::redirect "http://www.site.com/overhere/"

} else {

pool my_pool

}

My question is, can the two context switches co-exist within the same irule or will the switch for /stuff* overrule the entry for /stuff/place* ?





  • TCL evaluates switch statements in order, so you should put the more specific towards the top and the less specific at the bottom...

     

  • [root@orchid:Active] config  b rule myrule1 list
    rule myrule1 {
       when HTTP_REQUEST {
            switch -glob [string tolower [HTTP::uri]] {
                    "/stuff/place*" {
                            log local0. "URI is [HTTP::uri], /stuff/place* is triggered."
                    }
                    "/stuff*" {
                            log local0. "URI is [HTTP::uri], /stuff* is triggered."
                    }
                    default {
                            log local0. "URI is [HTTP::uri], default is triggered."
                    }
            }
    }
    }
    
    Sep 16 01:21:03 tmm tmm[7053]: Rule myrule1 : URI is /, default is triggered.
    Sep 16 01:21:07 tmm tmm[7053]: Rule myrule1 : URI is /stuff, /stuff* is triggered.
    Sep 16 01:21:14 tmm tmm[7053]: Rule myrule1 : URI is /stuff123, /stuff* is triggered.
    Sep 16 01:21:19 tmm tmm[7053]: Rule myrule1 : URI is /stuff/place, /stuff/place* is triggered.
    Sep 16 01:21:21 tmm tmm[7053]: Rule myrule1 : URI is /stuff/place123, /stuff/place* is triggered.
    
    
  • Colin_Walker_12's avatar
    Colin_Walker_12
    Historic F5 Account
    Your syntax actually looks just fine, you just need to combine the two with, as the above poster said, the more specific criteria first. Make sure you're closing the switch cases, and you're good to go.

     

     

    Colin