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

craddockchris's avatar
craddockchris
Icon for Altocumulus rankAltocumulus
Apr 22, 2024

iRule assistance

Dear community,

Could someone provide me with an example of an iRule that does the following:

 

I would like to have a single inbound VIP for API calls. These calls could go to one of 2 Pools depending on what is in the URI. How can I write an iRule that looks for a certain string in the URI and send the request to one pool or the other depending on what is in the URI?

 

Thank you. 

1 Reply

  • At its simplest...

    when HTTP_REQUEST {
        switch -glob -- [string tolower [HTTP::uri]] {
            "/thing-a/*" { pool "apiPoolA" }
            "/thing-b/*" { pool "apiPoolB" }
            default { HTTP::respond 400 content "Unsupported URI" noserver }
        }
    }

    i.e., in the HTTP_REQUEST event, read the URI, convert it to lower-case (for easier comparing) and compare it to one or more simple patterns

    If the URI starts with /thing-a/, forward to one specific backend pool; if it starts with /thing-b/, forward to another.

    If the URI does not match either of those patterns, respond with a basic HTTP error message.

    Note that, to the BIGIP, the term "URI" means "the path and querystring".  If you actually want just the path, try [HTTP::path]; if you want the hostname, try [HTTP::host]; or if you want both, consider "[HTTP::host][HTTP::uri]".

    If you need the scheme (i.e. if it is HTTP or HTTPS), it can be a little trickier.  Possibly [expr { [PROFILE::exists clientssl] ? "https" : "http" }].