Forum Discussion
Redirect every 4th reuqest to external site
We are in process of migrating our old website to a new website. The new website is hosted on a different set of servers. As per management decision at the initial phase we are asked to redirect 25% of the traffic to the new site.
I was thinking of using the rand funtion as below (www.abc.com - Old site ; www.xyz.com - new site):
when CLIENT_ACCEPTED {
if { rand() < 0.25 } {
HTTP::redirect "https://www.xyz.com"
}
}
But the problem is as www.xyz.com is hosted else where, the connection count never reaches 25% and all my traffic is being directed to the new site.
Did anyone else, implement it using irule for % directions. ?
Thanks,
Santosh.
- Kevin_StewartEmployeeI think the problem with this implementation is that CLIENT_ACCEPTED fires several times within a user session. So while some of the connections won't initially be redirected, they eventual will trigger the redirect logic and be sent to the other server.
when HTTP_REQUEST { if the tracking cookie doesn't exist, determine skip count and redirect if necessary if { not ( [HTTP::cookie exists TRACKER] ) } { log local0. "TRACKER cookie doesn't exist" set cookie flag set setcookie 1 detemine skip count (%25 of traffic) if { [table lookup -subtable TRACKERTABLE "track"] eq "" } { log local0. "tracker table doesn't exist - create it and set value to 1" table set -subtable TRACKERTABLE "track" 1 } elseif { [expr [table lookup -subtable TRACKERTABLE "track"] < 4] } { log local0. "tracker table value less than 4 - increment and allow local traffic" table incr -subtable TRACKERTABLE "track" } elseif { [table lookup -subtable TRACKERTABLE "track"] == 4 } { log local0. "tracker table equals 4 - reset to 1 and redirect to new site" table set -subtable TRACKERTABLE "track" 1 HTTP::redirect "https://www.xyz.com" } } else { log local0. "TRACKER cookie exists" } } when HTTP_RESPONSE { if setcookie exists, create TRACKER cookie in response if { [info exists setcookie] and $setcookie == 1 } { HTTP::cookie insert name TRACKER value 1 unset setcookie } }
- Kevin_StewartEmployeeI think the problem with this implementation is that CLIENT_ACCEPTED fires several times within a user session. So while some of the connections won't initially be redirected, they eventual will trigger the redirect logic and be sent to the other server.
when HTTP_REQUEST { if the tracking cookie doesn't exist, determine skip count and redirect if necessary if { not ( [HTTP::cookie exists TRACKER] ) } { log local0. "TRACKER cookie doesn't exist" set cookie flag set setcookie 1 detemine skip count (%25 of traffic) if { [table lookup -subtable TRACKERTABLE "track"] eq "" } { log local0. "tracker table doesn't exist - create it and set value to 1" table set -subtable TRACKERTABLE "track" 1 } elseif { [expr [table lookup -subtable TRACKERTABLE "track"] < 4] } { log local0. "tracker table value less than 4 - increment and allow local traffic" table incr -subtable TRACKERTABLE "track" } elseif { [table lookup -subtable TRACKERTABLE "track"] == 4 } { log local0. "tracker table equals 4 - reset to 1 and redirect to new site" table set -subtable TRACKERTABLE "track" 1 HTTP::redirect "https://www.xyz.com" } } else { log local0. "TRACKER cookie exists" } } when HTTP_RESPONSE { if setcookie exists, create TRACKER cookie in response if { [info exists setcookie] and $setcookie == 1 } { HTTP::cookie insert name TRACKER value 1 unset setcookie } }
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com