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

KT_271103's avatar
KT_271103
Icon for Nimbostratus rankNimbostratus
Sep 23, 2016

Irule

Can anyone check whether below statement is correct for given irule? Below Irule indicate the uri part would be lower case and as per 1st condition if it is empty "" then no URI insert. 2nd condition if it is some string after "/" then redirect will perform. when HTTP_REQUEST { switch -glob [string tolower [HTTP::uri]] { "" - "/" { HTTP::redirect "https://cache-monitor-AMG.com/home" } } }

 

3 Replies

  • It should be like this:

     

    when HTTP_REQUEST { 
    if { [string tolower [HTTP::uri]] ne "/" } {
    HTTP::redirect "https://cache-monitor-AMG.com/home" 
    } 
    }
    

     

  •  

    when HTTP_REQUEST {
       switch -glob [string tolower [HTTP::uri]] { 
            "" - 
            "/" { 
                HTTP::redirect "https://cache-monitor-AMG.com/home" 
            } 
        }
    }
    

     

    The switch matches cases against the expression. The string tolower normalizes the case of the Request-URI [1] to facilitate reliable comparison regardless of provided case [2]. The -glob allows for glob-style matching. [3] As you observe, the first case match is the empty string. The dash following it means that this case "falls through". That is, if the case matches, it will perform whatever action is specified for the case that follows it (unless that case is also a fall through, in which case it keeps falling through until it finds a case with an associated code branch).

    So, in this case, the outcome is the same regardless whether HTTP::uri is empty or a slash ("/"). The HTTP::redirect is an explicit redirect, which means a 302 status code is returned to the client, along with a Location header containing the new URL.

    [1] people sometimes confuse HTTP::uri with HTTP::path. The latter is probably what is intended in this case, since it is the path part of the Request-URI. The former would also include things like query parameters.

    [2] for the Request-URI, this is usually unnecessary, violates the HTTP RFC, and for these match cases costs execution cycles without adding value.

    [3] in this case, glob-matching is not needed and possibly costs cycles without adding value.