15-Apr-2021 05:25
Hi there,
I'm new to this forum and looking for some help, looking to create irule that will allow base path URL to redirect traffic to a certain pool.
example
incoming url https://xxxx.test.com/tester redirect to pool 1
incoming url https://xxx.test.com/tester/tester122 redirect to pool 2
Thanks,
Phong
15-Apr-2021 05:49
when HTTP_REQUEST {
set vurl [HTTP::host][HTTP::path]
if { $vurl starts_with "xxx.test.com/tester/tester122"} {
pool pool_name_a
} elseif { $vurl starts_with "xxx.test.com/tester"} {
pool pool_name_b
} else {
# no change to traffic
}
}
Probably something along these lines, with the more specific one first, as the less specific one otherwise will catch both.
Another point, if you have a lot of cases, like 20+, then it'd be a good idea to change to from repeated if statements to data groups.
If you don't need to test for domain you can remove the [HTTP::host] from the variable and the if statements
A lot of the time you can find inspiration to irules on clouddocs. For me "if" is bit more versatile, so I'll typically use it for these shorter rules. If you have a longer rule where you test a lot on the same variable then the Switch could be better.
The better advice would probably be to steer you towards http policies that can do this in a more user friendly/intuitive way... but I like irules.
15-Apr-2021 06:50
thanks Heino for your help, I'll give it a shot
Phong
15-Apr-2021 06:11
Something sort of below. Modify the pool names accordingly
when HTTP_REQUEST {
set baseuri [lindex [split [string tolower [HTTP::uri]] "/"] 1]
if { [HTTP::uri] eq "/$baseuri" } {
pool pool_1
} else {
pool pool_2
}
}
15-Apr-2021 06:50
thank you Sanjay for your support!
26-Apr-2021
17:36
- last edited on
24-Mar-2022
01:20
by
li-migration
- if you got an answer please Select As Best or Upvote contributing answers.
Thanks.