Learn F5 Technologies, Get Answers & Share Community Solutions Join DevCentral

Filter by:
  • Solution
  • Technology
Answers

Irule to redirect traffic based on path and uri

I have to redirect some traffic based on path and other based on uri. The irule should look something like this, but it´s not working. I should get working something like I post below. Any help?

when HTTP_REQUEST { switch -glob [string tolower [HTTP::uri]] { "/bla/blabla.gif" { pool pool-frontend } if { [HTTP::path } "/bla*" { pool pool-frontend2 } .... .... ....

Thanks in advance and regards, Pablo.

0
Rate this Question
Comments on this Question
Comment made 25-Sep-2015 by jgranieri 520
Why don't you use LTM policies, essentially F5 created these to make http parsing easy and not to need to code an irule... take a look its pretty self explanatory
0

Answers to this Question

placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

Why not use the switch function for it all. I believe the switch command uses the first match so you could do:

when HTTP_REQUEST { 
  switch [string tolower [HTTP::uri]] { 
            "/bla/blabla.gif" { pool pool-frontend }
            "/bla*" {pool pool-frontend2}
            default {pool default}
        }
} 
1
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

Your question is a bit vague, but this might push you in the right direction.

when HTTP_REQUEST { 

    #Set a variable to control if a pool has been chosen or not. 
    set chosen 0

    switch [string tolower [HTTP::uri]] { 
        "/bla/blabla.gif" { set chosen 1; pool pool-frontend }
    }

    #Check if the switch has chosen a pool
    if { $chosen != 1 } {

        if { [HTTP::path] starts_with "/bla" } { 
            pool pool-frontend2
        } else {
            pool default_pool
        }
    }
}

Please note that I have not tested the rule myself.

/Patrik

0