Forum Discussion

pjedrzejak's avatar
pjedrzejak
Icon for Nimbostratus rankNimbostratus
Aug 07, 2018

iRule for specific redirect

Hi, I got problem with preparing iRule uri redirect for specific servers.

Situation looks like:

  • S1 - serve two websites: /activ-admin and /activ-app
  • S2 - serve one website: /activ-app

On F5 i try to achive situation where:

  • VIP_IP/activ-app will forward to S1/activ-app
  • VIP_IP/activ-app2 will forward to S2/activ-app
  • VIP_IP/activ-admin will forward to S1/activ-admin

Now I write something like this:

when HTTP_REQUEST {
set start_uri [string tolower [HTTP::uri]]
    if { $start_uri starts_with "/activ-app2" } {
        HTTP::uri [string map { "app2" "app" } [HTTP::uri]]
        pool pool member 10.0.0.2 8080
        return
    } elseif { $start_uri starts_with "/activ-app" } {
        pool pool member 10.0.0.1 8080
    } elseif { $start_uri starts_with "/activ-admin" } {
        pool pool member 10.0.0.1 8080    
    } else { 
        drop
    }

}

But this solution is not working - all requests to VIP_IP/active-app2 are forwarded to S1/active-app How to make this redirect properly?

  • Hi,

    Here is an irule example for you :

    when HTTP_REQUEST {
        switch -glob [HTTP::path] {
            "/activ-app2*" {
                HTTP::uri [string map { "app2" "app" } [HTTP::uri]]
                pool member 10.0.0.2 8080
            }
            "/activ-app*" -
            "/activ-admin*" {
              pool member 10.0.0.1 8080  
            }
            default {
                drop
            }
        }
    }