Persistence via iRule not working

Hello

I am somewhat new to iRules, but have a general understanding how it should work.

I have a virtual server for a proxy service with a pool of 4 IP addresses without any default persistence set.

What I want is that when I specify a URI parameter (query string) when I request any URL is to be set to use a specific backend IP for ALL the traffic for the next say 5 min or until I close the browser. So that I can request Google and iRule will send all the traffic via just this proxy, regardless if I continue to use the parameter or not.

At the moment it only works on the initial request, but it does not set persistence for URLs that do not contain a proxy parameter in the URL…

Can someone help?

I cannot user source_addr persistence as there is another F5 before that, so that source IP will always be the same…

when HTTP_REQUEST {
 if { ([HTTP::uri] contains "useGRE=MO") || (([HTTP::header exists "Referer"]) and ([HTTP::header value Referer] contains "useGRE=MO"))} { 
  persist dest_addr 255.0.0.0 180
  node 1.2.1.1 80
 } elseif { ([HTTP::uri] contains "useGRE=MT") || (([HTTP::header exists "Referer"]) and ([HTTP::header value Referer] contains "useGRE=MT"))} { 
   
  persist dest_addr 255.0.0.0 180
  node 1.2.1.2 80
  
 } elseif { ([HTTP::uri] contains "useGRE=SO") || (([HTTP::header exists "Referer"]) and ([HTTP::header value Referer] contains "useGRE=SO"))} { 
   
  persist dest_addr 255.0.0.0 180
  node 1.2.1.3	80
 } elseif { ([HTTP::uri] contains "useGRE=ST") || (([HTTP::header exists "Referer"]) and ([HTTP::header value Referer] contains "useGRE=ST"))} { 
   
  persist dest_addr 255.0.0.0 180
  node 1.2.1.4 80

}}

Try using OneConnect in combination with Universal persistence.

You can use this as a framework and define it to suit your needs:

when HTTP_REQUEST {
  if { [HTTP::query] != "" } {
    persist uie [HTTP::query] 
    node <node ip>
  }
}