Forum Discussion

Beinwin_264402's avatar
Icon for Nimbostratus rankNimbostratus
Jan 10, 2017

iRule for HTTP Redirect



We are trying to run and iRule that if the URI doesn´t start with something, the F5 will redirecto to other URL. But there is a problem, we also need that the check could be with others start_withs I am triying with this rule:


when HTTP_REQUEST { if { ( not ([HTTP::uri] starts_with "/something") or ( not [HTTP::uri] starts_with "/something1") or ( not [HTTP::uri] starts_with "/something2") or ( not [HTTP::uri] starts_with "/something3")) } { HTTP::redirect "; } }


If I put that iRule, I get and err connection.


Do you know some way to acomplish this?


Thanks in advance


1 Reply

  • Do you have a default pool? Otherwise the F5 don't know where to send the request which would result in an error. Also, the if statement above is always true.

    Simple example:

    (not 1) or (not 2)

    • If it's 1 it means that it's not 2 = true
    • If it's 2 it means that it's not 1 = true

    Sure you don't want an "and" between the different cases? If that's the case you might want to rewrite it a bit. Try this one:

    when HTTP_REQUEST {

        Convert to lower case
        set uri [string tolower [HTTP::uri]]
        if { $uri starts_with "/something" or $uri starts_with "/something1" or $uri starts_with "/something2" or $uri starts_with "/something3" }{ 
            pool mypool
        } else {
            HTTP::redirect ""
    Depending on if the number of cases would grow or not I might consider putting the uri's in a data group list instead:
    1. Create a data group list of type string and populate it with all the uri's you want to match
    2. Create an irule, replace myurilist with whatever name you gave the data group list.

    irule definition:

    when HTTP_REQUEST {
        if { [class match [string tolower [HTTP::uri]] starts_with myurilist] }{
            pool mypool
        } else {
            HTTP::redirect ""

    What the rule does is to convert the current uri to lower case and the check if it starts with any of the entries in the data group list.


    It's not been tested or validated for syntax. 🙂