For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

adrian_171483's avatar
Jun 25, 2015

irule syntax check

Got a check on an Irule.. the rule needs to forward http requests not containing the URI /dashboard onto the default pool someother-http-farm.

 

If the http request does contain /dashboard in the URI, then redirect it to https retain the hostname / URI string

 

This is the Irule I propose to use..

 

when HTTP_REQUEST { if { [string tolower [HTTP::uri]] contains "/dashboard*" } { HTTP::redirect "https://[HTTP::host][HTTP::uri]" } else

 

default { pool someother-http-farm } } }

 

5 Replies

  • you want this:

     

    • don't use wildcard in contains, starts_with, ends_with equals conditions
    • wrong syntax in else --> removed default
    • I removed one closing bracket

       

      when HTTP_REQUEST { if { [string tolower [HTTP::uri]] starts_with "/dashboard" } { HTTP::redirect "https://[HTTP::host][HTTP::uri]" return } else { pool someother-http-farm } }

       

  • when HTTP_REQUEST { if { [string tolower [HTTP::uri]] starts_with "/dashboard" } { HTTP::redirect "https://[HTTP::host][HTTP::uri]" return } else { pool someother-http-farm } }

     

    I also need a rule that can have sioe other conditions..

     

    Can I use

     

    when HTTP_REQUEST { if { [string tolower [HTTP::uri]] starts_with "/dashboard" or "/something" or "/something"} { HTTP::redirect "https://[HTTP::host][HTTP::uri]" return } else { pool someother-http-farm } }

     

  • the best way with multiple values is switch: ( - at the end of choices is like a "or" )

    when HTTP_REQUEST {
        switch -glob -- [string tolower [HTTP::path]] {
            "/dashboard*" -
            "/something*" -
            "/somethingelse*" { 
                HTTP::redirect "https://[HTTP::host][HTTP::uri]"
                return
                }
            default { pool someother-http-farm } 
        }
    }
    
  • ok thanks that's brilliant... once the https redirect is done then we would need to drop the /URI onto a different farms from the https Virtual server: so I am thinking this ?

     

    when HTTP_REQUEST { if { [string tolower [HTTP::uri]] starts_with "/dashboard" or "/something"} { pool some-farm } if { [string tolower [HTTP::uri]] starts_with "/somethingelse" } { pool someother-farm } default {

     

    pool default-farm }

     

  • OK,

    last answer... next time, try to find yourself... there is a search icon on the top right corner... enter "irule wiki"... I swear you will find everything about irules...

    when HTTP_REQUEST {
        switch -glob -- [string tolower [HTTP::path]] {
            "/dashboard*" -
            "/something*" { 
                HTTP::redirect "https://[HTTP::host][HTTP::uri]"
                return
                }
            "/somethingelse*" { pool someother-farm } 
            default { pool someother-http-farm } 
        }
    }