Forum Discussion

Annsar_Akhtar's avatar
Annsar_Akhtar
Icon for Nimbostratus rankNimbostratus
Nov 24, 2016

F5 irule getfield to split url and pass to different pools

Hi All

 

I am using the getfield to split a url and see if I can get the traffic to a different pool. The challenge I have is that /test/// needs to be served from a different pool from the default and anything else need to be served from the default pool (i.e. /test/*//).

 

I have tried the below but I am seeing all request are being served from the TESTPOOL

 

when HTTP_REQUEST { set level3 [getfield [HTTP::uri] "/" 3] set level4 [getfield [HTTP::uri] "/" 4] set level4 [getfield [HTTP::uri] "/" 5]

 

if {[string tolower [HTTP::uri]] starts_with "/test/" && ([string tolower [HTTP::uri]] contains "$level5") }{ } elseif {[string tolower [HTTP::uri]] starts_with "/test/" && ([string tolower [HTTP::uri]] contains "$level3") &&! ([string tolower [HTTP::uri]] contains "$level5") }{ pool TESTPOOL } } }

 

Any pointers or a better approach much appreciated

 

3 Replies

  • Hi Annsar,

    If you want to forward URIs with 5 or more path segments to a different pool, then take a look to the iRule below...

    when HTTP_REQUEST { 
        if { ( [string tolower [HTTP::path]] starts_with "/test/" ) and ( [llength [split [HTTP::path] "/"]] > 5 ) } then {
            pool TESTPOOL
        } else {
            pool DEFAULTPOOL
        }
    }
    

    Note: I hope that I got the point of your question? If not then please clarify the question a little bit more detailed with some samples URIs...

    Cheers, Kai

  • Thank Kai

     

    In terms of examples:

     

    /test/level/level2 or /test/level/level2/level3 needs to be routed to another pool, any requests for /test/level/level2/level3/level4 or /test/level/level2/level3/level4/level5 etc.. will need to be served by the default pool.

     

    I wonder if I could have used:

     

    when HTTP_REQUEST { if { ( [string tolower [HTTP::uri]] starts_with "/test/" ) and ( [llength [split [HTTP::path] "/"]] > 5 ) } then { pool TESTPOOL } else { pool DEFAULTPOOL } }

     

  • Thanks Kai, I have gone with the below.

     

    when HTTP_REQUEST { if { ( [string tolower [HTTP::path]] starts_with "/test/" ) and ( [llength [split [HTTP::path] "/"]] > 5 ) } then { pool TESTPOOL } }

     

    I am just going to get added into a test environment so I can test it properly.

     

    I will keep you posted and thanks for your help