Forum Discussion

souravkayal_287's avatar
souravkayal_287
Icon for Nimbostratus rankNimbostratus
Jun 02, 2017

help with IRULE commands

So i have a requiremnt of an irule where if the uri "xyz" i have a condition to not use any peristence , string tolower [HTTP::uri]] starts_with "xyz" . Now i have to add a few more uri like /abc/ etc can i use the same conditions with and operator or use switch -glob command. please help with the syntax as i am not so good with scripting and getting errors

 

  • Hello, something like this?

    when HTTP_REQUEST {
        switch -glob [string tolower [HTTP::uri]] {
            "/uristarts*" -
            "*/uricontains/*" -
            "*/uriends" {
                persist none
            }
        }
    }
    

    Regards.

  • Sourav, If I understood your logic, the switch block should be:

    when HTTP_REQUEST { 
        switch -glob [string tolower [HTTP::uri]] {
            "/admin/*" -
            "/ads/*" -
            "/eavcs/*" -
            "/eaon/*" {
                persist none
                pool name
            }
            "/" {
                HTTP::redirect "https://website.com/admin";
            }
            default {
                if { [HTTP::cookie exists BIGipServer~pool pool_com] } {
                    scan [HTTP::cookie BIGipServer~pool pool_com] {%[^.].%d.%d} myIpE myPortE unused
                    set myIpH [format %08x $myIpE]
                    set myIpD1 [expr 0x[substr $myIpH 6 2]]
                    set myIpD2 [expr 0x[substr $myIpH 4 2]]
                    set myIpD3 [expr 0x[substr $myIpH 2 2]]
                    set myIpD4 [expr 0x[substr $myIpH 0 2]]
                    set myIpD "$myIpD1.$myIpD2.$myIpD3.$myIpD4"
                    set myPortH [format %04x $myPortE]
                    set myPortD [string trimleft [expr 0x[substr $myPortH 2 2][substr $myPortH 0 2]] 0]
                    node $myIpD $myPortD
                }
            }
        }
    }