Forum Discussion

sandy16's avatar
sandy16
Icon for Altostratus rankAltostratus
Jul 02, 2015

irule help for inserting uris and redirecting to diff pools.

Hi Experts, I am trying to satisfy two requirements into 1 irule - 1) URI insertion. So to re-direct client from https://example.com to https://example.com/weblogin. This needs to go to the default Pool. 2) If there is a URI "dev" found, omit the step 1 insertion but send to a different pool. Example - https://example.com/dev goes to a different pool.

i tried this -

when HTTP_REQUEST {
  switch -glob [string tolower [HTTP::uri]] {
    "dev" { 
      pool P-DEV-POOL
    } 
    default { 
      pool P-EXAMPLE-POOL
    }
  } 
}

The uri based pool re-direction/forwarding is working but the uri insertion for step 1 is not. How to CAT them together into 1 irule?

 

2 Replies

  • Unfortunately, the code paste was a bit mangled, so I apologize if I miss something. I will say, though, that I don't see a branch where you insert or redirect.

    To start, are you interested in performing an HTTP Redirect (i.e., send back a 3xx response with a Location header), or transparent URI rewrite (change the URI before proxying the message to the pool member)? The code differs according to which you require.

    If you are using 11.4.0 or greater, you can accomplish all of your objectives using a Local Traffic Policy, rather than an iRule:

    https://support.f5.com/kb/en-us/solutions/public/15000/000/sol15085.html

    This has several advantages: 1. it is likely faster than an iRule; 2. it is part of the standard config; and 3. it doesn't require code debugging or code expertise for those that need to understand it.

    If you cannot use a Local Traffic Policy, the following iRule should accomplish what you want, assuming that an HTTP Redirect is what you're after:

     

    when HTTP_REQUEST {
       switch [HTTP::uri] {
          "/dev" -
          "/dev/*" {
             pool P-DEV-POOL
          }
          
          "/" -
          "" {
             HTTP::redirect "https://example.com/weblogin"
          }
       }
    }
    

     

    Notice a few things:

    1. I assume you want the dev pool for any arbitrary URI beginning with the /dev path element;
    2. the string tolower isn't necessary unless all capitalization permutations of "dev" must be supported;
    3. I assume that you want to redirect to "/weblogin" only when the URI is "/" (or empty). If you want to go there regardless of the URI, then your use of "default" is naturally correct;
    4. I don't explicitly name the default pool. There is no need to do so if the Virtual Server default pool is set.