I am in the process of moving from a Cisco CSS to the F5 and I have an interesting Redirect issue. On the CSS, I have a content rule that has two services associated with it. Each service is of a redirect type and each goes to a different URL. Basically, it load balances two redirects. I need to do the same thing on the F5. I need to configure an iRule that will round-robin requests to two different redirects. Here is an example of what we’ve tried…
when RULE_INIT {
set ::whichone 0
}
when HTTP_REQUEST {
switch $::whichone {
0 {
HTTP::redirect "http://Server1/blah"
}
1 {
HTTP::redirect "http://Server2/blah"
}
}
set ::whichone [expr ! $::whichone]
}
Basically it’s setting a global variable and toggles it between 0 and 1 on each http request. Then, depending on the current value it issues the appropriate redirect.
Or, you could do the same without the expr command and using a default case to avoid a second comparison on the value 1.
when RULE_INIT {
set ::whichone 0
}
when HTTP_REQUEST {
switch $::whichone {
0 {
HTTP::redirect "http://Server1/blah"
set ::whichone 1
}
default {
HTTP::redirect "http://Server2/blah"
set ::whichone 0
}
}
}
So I have another piece I was just asked to address with this. Is there a way to do a health check of the site I’m redirecting to prior to sending the client there? Something like…
If you have that site defined as a pool member (you can add as a dummy host), then you can use the LB::status command as a conditional before redirecting. Here’s the wiki page for the LB commands:
What Joe gave me above works perfectly, but I’d like to add one more piece to that. So I want the iRule to redirect to two different sites and technically load balance them which is what Joe’s code does. But now I’m curious if, before it sends the user to the redirect site, can the iRule do a health check of that site and if it’s down, send the user to the other redirect site.
I can’t define sample.domain.com/blah as a node or a pool member. I can do sample.domain.com. I’m trying to redirect to another site and a page on that site.
There isn’t a good way that I can think of to do health-checks on remote sites. It’s pretty easy to redirect users to wherever you want, but health-checking remote systems is a little more tricky.
There isn’t a good way that I can think of to do health-checks on remote sites. It’s pretty easy to redirect users to wherever you want, but health-checking remote systems is a little more tricky.
Colin
I’m confused by this statement, Colin.
What’s the difference?
If you setup a pool with a member that’s remote (e.g. sample.domain.com) and setup a health monitor that performs ‘GET /blah’, surely this will do what the OP wanted…? mark the node down if the remote site doesn’t respond to the GET /blah, thereby enabling the LB::status check.
When sending the redirect back to the client, the client will initiate a new connection to a new destination. --> Server1 or Server2 Therefore no control over the connection within this irule anymore.
I think you now found the issue, that you would not reach the server 1 or 2 if it is down.
So i do not think you should work with redirect at all. Do you have control over those servers ?
Why do you need to work with a redirect ? Just Loadbalance the Servers with a pool and replace the hostheader if needed. (don´t think you need to)
Please explain us about the goal of the redirects a bit more that we are able to help