I think in this particular situation we shouldn't get too much of a problem, as the connection coming into the LTM is an initial connect from a URL in the application. Once it gets redirected, the real action happens, so a user (probably) only sends one connection to the load balancer.
If the clients are generally going to establish a TCP connection, send a single HTTP request and the close the connection, you wouldn't want to reset the redirect number on every new TCP connection. Doing so would mean that most clients would get redirected only to the first URL. If you use a global counter of some sort (global variable, stats profile field or session table entry) then there should be even distribution of redirects to the first and second URLs.
Here is an example which uses a global variable declared in RULE_INIT to track the redirects.
Example of round robin redirection
when RULE_INIT {
Initialize the redirect counter to 0
set ::redirect_counter 0
}
when HTTP_REQUEST {
Check the counter value
switch $::redirect_counter {
0 {
Value was 0, redirect to first URL with cache control headers set to prevent caching of response
HTTP::respond 302 Location "http://firsthost.domain.com" Cache-Control No-Cache Pragma No-Cache
set ::redirect_counter 1
}
1 {
Value was 1, redirect to second URL with cache control headers set to prevent caching of response
HTTP::respond 302 Location "http://secondhost.domain.com" Cache-Control No-Cache Pragma No-Cache
set ::redirect_counter 0
}
}
}
Or if you configure the IP address(es) of the two domains in a pool with round robin load balancing, you could configure an HTTP(S) monitor to check the response of each server and use an iRule like this to send the redirects. You would
when HTTP_REQUEST {
For a load balancing selection from the VIPs default pool
This assumes you've set the pool's load balancing algorithm to round robin
switch [LB::select] {
"1.1.1.1" {
Send client a 302 redirect with the hostname which corresponds to the 1.1.1.1 server IP
HTTP::respond 302 Location "http://firsthost.domain.com" Cache-Control No-Cache Pragma No-Cache
}
"2.2.2.2" {
Send client a 302 redirect with the hostname which corresponds to the 2.2.2.2 server IP
HTTP::respond 302 Location "http://secondhost.domain.com" Cache-Control No-Cache Pragma No-Cache
}
default {
Take some default action if both servers are marked down?
}
}
}
Aaron