Forum Discussion

Chris_Olson's avatar
Chris_Olson
Icon for Nimbostratus rankNimbostratus
Nov 10, 2006

URI and pool redirection

Having trouble with the following iRule. Any help is appreciated.

 

 

when HTTP_REQUEST {

 

set uri [string tolower [HTTP::uri]]

 

if { $uri starts_with "/app1" } {

 

HTTP::uri [string map -nocase {"/app1" "/prod/login.cmdx"} $uri]

 

Pool Prod_EE_11

 

}

 

Elseif { $uri starts_with "/app2" } {

 

HTTP::uri [string map -nocase {"/app2" "/prod/login.cmdx"} $uri]

 

Pool Prod_EE_10

 

}

 

Else {

 

HTTP::uri [string map -nocase { * "/app1/login.cmdx"} $uri]

 

Pool Prod_EE_11

 

}

 

}

6 Replies

  • What trouble are you having? You can add some log statements to see which condition is being met and what change is being made to the URI:

    log local0. "\$uri was $uri"

    
    when HTTP_REQUEST {
       set uri [string tolower [HTTP::uri]]
       if { $uri starts_with "/app1" } {
          log local0. "\$uri was $uri"
          HTTP::uri [string map -nocase {"/app1" "/prod/login.cmdx"} $uri]
          pool Prod_EE_11
       }
       elseif { $uri starts_with "/app2" } {
          log local0. "\$uri was $uri"
          HTTP::uri [string map -nocase {"/app2" "/prod/login.cmdx"} $uri]
          pool Prod_EE_10
       }
       else {
          log local0. "\$uri was $uri"
          HTTP::uri [string map -nocase { * "/app1/login.cmdx"} $uri]
          Pool Prod_EE_11
       }
    }

    Aaron
  • While the below script compiles OK., it does not function as needed. Adding the suffix to the end of the URI only works if you manually type in HTTPS. I'm guessing this has to do with this script itself or another redirect script. Here is the situation:

     

    We have two Vitrual servers with the same address, one https and one http. The HTTP server has the following redirect to https.

     

     

    when HTTP_REQUEST {

     

    HTTP::redirect https://[getfield [HTTP::host] ":" 1][HTTP::uri]

     

    }

     

     

    The HTTPS virtual server has the following applied:

     

     

    when HTTP_REQUEST {

     

    set uri [string tolower [HTTP::uri]]

     

    if { $uri starts_with "/prod11" } {

     

    log local0. "\uri was $uri"

     

    HTTP::uri [string map -nocase {"/prod11" "/App/login.cmdx"} $uri]

     

    pool App_EE_11

     

    }

     

    elseif { $uri starts_with "/prod10" } {

     

    log local0. "\uri was $uri"

     

    HTTP::uri [string map -nocase {"/Prod10" "/App/login.cmdx"} $uri]

     

    pool App_EE_10

     

    }

     

    else {

     

    log local0. "\uri was $uri"

     

    HTTP::uri [string map -nocase { * "/App/login.cmdx"} $uri]

     

    Pool App_EE_11

     

    }

     

    }

     

     

    IF I type https in the URL, the pool is correctly evaluated. If I type in HTTP in the URL it doesn’t appear to evaluate the rule correctly. What am I missing?

     

  • Have you looked at the logs? If typing in the https:// is working but using your redirect is not, then there are a couple of options:

    1. Your HTTP::redirect is not using the correct string.

    I'd add some logging in the first iRule to make sure the redirect is correct.

    when HTTP_REQUEST {
      set redir_url https://[getfield [HTTP::host] ":" 1][HTTP::uri]
      log local0. "redirecting to $redir_url"
      HTTP::redirect https://[getfield [HTTP::host] ":" 1][HTTP::uri]
    }

    2. The redirect isn't making it to your second virtual. Add another log statement at the top of your second iRule to make sure control is making it in there.

    when HTTP_REQUEST {
      set uri [string tolower [HTTP::uri]]
      log local0. "found uri: $uri"
      if { $uri starts_with "/prod11" } {
      ...

    Run some traffic through the http virtual and look at the logs and hopefully that will shed some light on the issue.

    -Joe
  • I'm getting close but have a question regarding using two redirects. We are set up with two virtual servers, same IP. One for 80, one for 443. I applied a generic redirect from http to https on the 80 server.

     

    On the 443 server, I have an irule directing them to a pool based on the "/version" that the client enters depending on what version they are running. This way, I have one SSL, one Virt address for many different versions of the same software. The http to https redirect does not appear to work or conflicts with the second redirect on the https virtual.

     

    Do I need to come up with a single irule that will redirect to https AND a pool member based on the version or should the two irules work together as shown above?
  • Deb_Allen_18's avatar
    Deb_Allen_18
    Historic F5 Account
    No, you will need both iRules, one applied to each virtual server. The iRules should not interfere with each other, as they are applied to different virtuals and only one of the iRules will be triggered for any given connection. (Keeping in mind that a new connection to 2nd virtual will be established after redirection from first.) In general, you can't specify in one iRule the action that should be taken by another iRule for a different connection on a different virtual server.

     

     

    Did you follow Joe's advice about adding some logging to the first iRule? The resulting log entries should be helpful. Post back with your iRules and the logged results if it still isn't making sense.

     

     

    HTH

     

    /deb