irule for load balance traffic based on query string

Hello team ,

I am looking for irule to loadbalance traffic based on query string from host header .For example

Example Domain this particluar request need to go to webserever 1 of my http_pool ,similarly www.abc.com?silo=2 needs to go to webserver 2 on my http_pool .All sites are coming to same VIP address ,but requirement here is to load balance based query string in host header .I did try HTTP::query string commands in irule ,but its not working .

silo=1 will be webserver1 silo=2 will be webserver2 silo=3 will be webserver3

Regards puluck

Hi,

this irule read the server in the query parameter and search it’s IP in the static::web servers array

when RULE_INIT {
    array set static::webservers {
        1   1.1.1.1
        2   1.1.1.2
        3   1.1.1.3
    }
}

when CLIENT_ACCEPTED { 
    set default_pool [LB::server pool]
}

when HTTP_REQUEST {
    set target_member [URI::query [HTTP::uri] silo]
    if {!($target_member eq "") && [info exists static::webservers($target_member)} {
        pool $default_pool member $static::webservers($target_member)
    }
}