Forum Discussion

matt_cole_24635's avatar
matt_cole_24635
Icon for Nimbostratus rankNimbostratus
Jan 03, 2017

iRules vs Polices

I am trying to replicate the following iRule with a LTM Policy. iRule works, policy doesnt work. Does it support regex? How can I match just a / with nothing before or after without regex? iRule:

if {[string tolower [HTTP::uri]] matches_regex {^/$}} { HTTP::redirect "; }}

Policy:

rules {
    "Default Page Redirect" {
        actions {
            0 {
                http-reply
                redirect
                location http://example.com/external/example.jspx
            }
            1 {
                log
                write
                facility local0
                message "tcl: [HTTP::path]"
                priority debug
            }
        }
        conditions {
            0 {
                http-uri
                path
                values { ^/$ }
            }
        }
    }

1 Reply

  • Hi,

    First, the irule is working but is not optimized. Regex must only be used if necessary and / in uppercase and lowercase always equals / :

    if {[HTTP::uri] equals "/"} { 
        HTTP::redirect "https://example.com/external/example.jspx"; 
    }
    

    in the policy, this is the same:

    rules {
        "Default Page Redirect" {
            actions {
                0 {
                    http-reply
                    redirect
                    location http://example.com/external/example.jspx
                }
                1 {
                    log
                    write
                    facility local0
                    message "tcl: [HTTP::path]"
                    priority debug
                }
            }
            conditions {
                0 {
                    http-uri
                    path
                    values { / }
                }
            }
        }