Forum Discussion

Svevak_211593's avatar
Svevak_211593
Icon for Nimbostratus rankNimbostratus
Oct 30, 2018

URL forwarding to dedicated nodes

Hello,

 

I am still very new to iRules, and I am trying to get the code correct for a simple URL redirect. I would like to route certain URL-paths to dedicated servers in the same pool.

 

For example path /foo/ should only go to server "a". Path /bar/ to server "b". And both servers "a" and "b" are in the same pool.

 

Any help with this will be greatly appreciated:)

 

Thanks!

 

  • Snl's avatar
    Snl
    Icon for Cirrostratus rankCirrostratus

    try below (not tested) assume server a - 10.1.1.1 port 8080 & server b 11.1.1.1 port 8080

    when HTTP_REQUEST {
      if { [string tolower [HTTP::uri] ] starts_with "/foo" } {
        node 10.1.1.1 8080 }
    elseif { [string tolower [HTTP::uri] ] starts_with "/bar" } {
        node 11.1.1.1 8080 }
    }
    
  • Hello,

     

    You could try doing something like the following code

     

    when HTTP_REQUEST {
        if { [HTTP::path] contains "/bar" } {
            log local0. "pool_a"
            pool server_a
        } elseif { [HTTP::path] contains "/foo"}{
            log local0. "pool_b"
            pool server_b
        } else {
            log local0. "pool_default"
            pool server_default
        }
    }

    If you want to redirect to specific node inside the pool then write

     

    node 172.x.x.x XXXX

    Hope it helps