iRule | route to another pool according to URI
Hello guys
I'm trying to write an iRule that route the traffic if the end user hit a specific URI. This specific URI has a pattern inside it and according to this pattern I'm doing the match.
But here is the situation:
1- That URI is changed after the user click on any link inside the page and then the F5 re-route him again to the VS default pool.
I need the user to persist all the time to the specific pool the iRule route him to.
2- If the client tries again to different "branchcode" , then route to the default pool.
Here is what I wrote at first but not working:
when HTTP_REQUEST {
if { [URI::query [string tolower [HTTP::uri]] "branchcode"] equals "123"} {
log local0. "my_pool was selected"
pool my_pool
}
else {
pool default_pool
}
}
It worked only at the begining when the user hit the URI with "branchcode" 123, but then if he click on any link inside the webpage, he's being redirected to the VS default pool , because the URI doesn't has the "branchcode" inside it anymore.
And then I added the:
persist source_addr
Although it should take it from the VS but didn't work also.
And then I tried to change it to this one:
when HTTP_REQUEST {
if { [URI::query [string tolower [HTTP::uri]] "branchcode"] equals "123"} {
persist source_addr 720
set static::myclientip [IP::client_addr]
pool my_pool
}
elseif { [info exists "static::myclientip"] } {
pool my_pool
}
}
But the thing is that after I wrote this iRule all users are being routed to the specific pool "my_pool". which I don't understand why.
Looks like the elseif always matches .....
Also, if the user closes the page or manually change the branchcode to something else.. he still hit the "my_pool" , i think because the persistence timeout has not reached the 720 seconds..
Anyone please can help to tune the iRule and modify it?
Thanks