Technical Forum
Ask questions. Discover Answers.
Showing results for 
Search instead for 
Did you mean: 

iRule for load balancing to different virtual server depending on the URI path


Hi Guys,

I have three Virtual Server to be configured on our LTM's which are running on the version 15.1.7. One virtual server is facing to client (let say VS-A) and contains two virtual server (let say VS-B and VS-C) that should be load balance.

VS-B and VS-C need to load balance on the VS-A but the incoming traffic should be clasify use the uri /path.

The conditions like this:

if the uri contains /aa, /bb, /cc will be forward and load balance to VS-B and VS-VS-C.

I tried to make irules like this:

if { [HTTP::uri] contains "/aa,/bb,/cc" } {
virtual VS_B
} else {
virtual VS_C

But the results is traffic from the client always going to the VS-B, so the load balancing doesn't have running.

I don't know it can be configured with the iRules or not, since I am not an expert in writing the iRules can anyone suggest me with the iRules that helps working the VIP as mentioned above.

Appreciate any kind your insight.




Your description is hard to follow. Can you please provide a flow chart for how you want the different URIs to map to what paths / locations / IPs? Or perhaps a better flow to facilitate understanding of the issue.

Hi @whisperer ,

Here are the flow traffic:


Flow for devcentral.jpg


Appreciate for your help.


@Bobow This might work but what you are attempting to do seems a whole lot more complicated this way and can most likely be done cleanly by only matching the URI path to a specific destination VS rather than letting load balancing occur and then changing the HOST and URI path after the fact.

when LB_SELECTED priority 500 {

    set SELECTED_POOL_MEMBER[LB::server addr]


when HTTP_REQUEST_SEND priority 500 {

    if { ${SELECTED_POOL_MEMBER} == vs_b_ip } {
        HTTP::uri [string map {"/aa" "/"}[HTTP::uri]]
        HTTP::host [string map {"" ""}[HTTP::host]]
    } elseif { ${SELECTED_POOL_MEMBER} == vs_c_ip } {
        HTTP::uri [string map {"/aa" "/"}[HTTP::uri]]
        HTTP::host [string map {"" ""}[HTTP::host]]


As many have said before "Just because it can be done with an iRule doesn't mean you should." so you might want to look at alternatives that work a bit better. For instance you might consider allowing the servers to listen for the orignal host and uri rather than mapping strings to assist in resolving the issue.

If the web servers use absolute paths with an internal host name or something similar, I can see why the F5 has to rewrite this on the server side of the connection. Also, if the web server doesnt support virtual hosting. Well, if either of those cases are true.... it is 2023 last time I checked. Either a) update the web server technology or b) force the web app developers to write better code. I would not use such a hack job to make this work for the sake of making it work. The complexity will result in other things breaking. Been there, done that.

Hi @Paulius ,

Appreciate for your insight.

I will tried that your iRules suggestion first.
Thank You!

@Bobow Hopefully this works but as @whisperer stated, just because it works doesn't mean it's the appropriate course of action. You are better off allowing the destination servers to handle this rather than the F5 using some bandage method that will most likely cause huge problems for you in the future.


Similler case, need the irules for this one anyone