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

Filter by:
  • Solution
  • Technology
Answers

irule to select pool based on url

Hi All,

I am new to f5 irules.

I need an irule that can select which pools to go base on the url.

Example :

url1 : https://www.abc.com

url2 : https://www.abc.com/dashboard

Both of the url will resolve into 10.10.10.10

When the user hit url1 : https://www.abc.com , it will go to pool_A.

When the user hit url1 : https://www.abc.com/dashboard , it will go to pool_B.

Thanks.

0
Rate this Question
Comments on this Question
Comment made 30-Jul-2015 by janlaw 137
Hi All, Thanks for the help, i will try this irules asap. The members in both of the pools are the same, just that the ports are different. pool_A is for 443 and pool_B is for 8000. Should i enable the port translation at the virtual sever, so that it will translate from 443 to 8000 if it hit pool_B? Thanks.
0

Answers to this Question

placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

Here's a quick iRule example:

when HTTP_REQUEST {
    switch -gob [string tolower [HTTP::uri]] {
        "/dashboard*" { pool pool_B }
        "/" { pool pool_A }
        default { pool pool_A }
    }
}

But then you can also do this task with an LTM policy and no iRules at all. Remember to enable OneConnect in the virtual server and in the associated HTTP profile to be able to do this context-based load balancing.

0
Comments on this Answer
Comment made 31-Jul-2015 by janlaw 137
Hi Kevin, May i know what is OneConnect for and why is a must to enable it? Thanks
0
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

Something like this: when HTTP_REQUEST { switch [string tolower [HTTP::uri]] { "/" { pool pool_A } "/dashboard" { pool pool_B } default { } } }

You can then add others as required, if you want do do partial matches using regex

0
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

If I may add,

If you do wildcard matching - the switch -glob option (which is actually not regex), you should put the more specific URIs first. If you put "/*" first, then all requests will match this.

You don't have to specify a default action, but it's recommended.

0
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

Hi All, Thanks for the help, i will try this irules asap.

The members in both of the pools are the same, just that the ports are different. pool_A is for 443 and pool_B is for 8000.

Should i enable the port translation at the virtual sever, so that it will translate from 443 to 8000 if it hit pool_B?

Thanks.

0
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

Should i enable the port translation at the virtual sever, so that it will translate from 443 to 8000 if it hit pool_B?

You absolutely must enable port translation in the VIP if you want this to work. Is it also that one pool is doing SSL and the other is not?

0
Comments on this Answer
Comment made 30-Jul-2015 by janlaw 137
I will enable the port translation. both of the are doing SSL.
0
Comment made 30-Jul-2015 by janlaw 137
is there any problem that i will face??
0
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

is there any problem that i will face??

Not if both are doing SSL. I was thinking that maybe one was doing SSL (the 443 pool) and one was not (the 8000 pool), in which case you'd have to also enable or disable the server SSL profile in the VIP according to the pool selection.

0
Comments on this Answer
Comment made 30-Jul-2015 by janlaw 137
mind i ask this question. I will need to enable the irules in the virtual server. so do i still need to select pool in the virtual server or leave it empty?
0
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

If you're controlling ALL pool access form the iRule, then no you don't have to add the pool to the VIP.

0
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

May i know what is OneConnect for and why is a must to enable it?

When you load balance to a server in a pool, the BIG-IP establishes direct TCP connections with that pool member (as a proxy would). If you're doing "content switching", where you're sending traffic to different pools based on some request criteria, you may run into a situation where the BIG-IP has an established TCP connection with one pool member and won't immediately sever that connection and start a new one somewhere else. The OneConnect profile (applied in the virtual server and in the associated HTTP profile) allows you to safely switch between pool members.

Please see the following solution article for more details:

https://support.f5.com/kb/en-us/solutions/public/7000/200/sol7208.html?sr=47331370

0