The reason your redirect to “/testpage” isn’t working is because you aren’t providing the full URL and you are using “starts_with” instead of “eq”. When you use “starts_with” “/” you will receive a redirect for every single path that comes to the F5 causing a redirect loop, which is what you are probably experiencing. I have come up with the following rule that should work, assuming this is HTTP and not HTTPS, if it’s HTTPS you just have to replace “http://” with “https://” and it will work appropriately.
when HTTP_REQUEST priority 500 {
if { [active_members pool1] != 0 } {
if { [HTTP::uri] == "/" } {
HTTP::redirect "http://[HTTP::host]/testpage"
}
} else {
if { ( ( [class match [IP::client_addr] eq "whitelist"] ) && ( [active_members pool2 ] > 0 ) ) } {
pool pool2
} else {
HTTP::respond 503 content [ifile get "applicationdown.html"]
}
}
}
Thanks for your response , above logic works only when pool1 members are not equal to zero then simply it goes to uri redirect ,but when the else condition is met and traffic is going to pool2 , i even want the HTTP::redirect “https://[HTTP::host]/testpage”. If I apply If for pool2 too its not working .Can you assist me.
If that’s the case then your original iRule with the “==” correction on the URI match should work. I have also made some formatting changes as well so I would use the iRule in this comment.
when HTTP_REQUEST priority 500 {
if { [HTTP::uri] == "/" } {
HTTP::redirect "http://[HTTP::host]/testpage"
}
if { [active_members pool1] == 0 } {
if { ( ( [class -- match [IP::client_addr] == "whitelist"] ) && ( [active_members pool2 ] > 0 ) ) } {
pool pool2
} else {
HTTP::respond 503 content [ifile get "applicationdown.html"]
}
}
}
redirect is working as expected but when both pools are down i dont see traffic going to HTTP::respond 503 content [ifile get “applicationdown.html”] . I get connection reset can’t reach the page.
when HTTP_REQUEST priority 500 {
if { [HTTP::uri] == “/” } {
HTTP::redirect “https://[HTTP::host]/testpage”
}
if { [active_members pool1] == 0 }{
if { ( ( [class match [IP::client_addr] eq “whitelist”] ) && ( [active_members pool2 ] > 0 ) ) }
{ pool pool2
}
else {
log local0. “applicationdown”
HTTP::respond 503 content [ifile get “applicationdown.html”]
}
}
}
lb err tmm[31148]: 01220001:3: TCL error: /Common/applicationdown-irule <HTTP_REQUEST> - Operation not supported. Multiple redirect/respond invocations not allowed (line 1) invoked from within “HTTP::respond 503 content [ifile get “applicationdown.html”]”
lb err tmm[31148]: 01220001:3: TCL error: /Common/applicationdown-irule <HTTP_REQUEST> - Operation not supported. Multiple redirect/respond invocations not allowed (line 10) invoked from within “HTTP::respond 503 content [ifile get “applicationdown.html”]”
Paulius , thankyou so much for looking into this , but the problem with the above logic is when both the pools are down users still need to get the maintenance page but when i try accessing the url abc.test.com -- I get connection rest page cannot be displayed when i access https://abc.test.com/testpage --- it displays me the application down message from the log statement . Dont see any issues with the syntax of the above irule but when both pools are down i see vip is marked down so the else statment is not getting executed i guess.
tmm[31148]: 01220001:3: TCL error: /Common/test-irule <HTTP_REQUEST> - Operation not supported. Multiple redirect/respond invocations not allowed (line 10) invoked from within “HTTP::respond 503 content [ifile get “applicationdown.html”]”
It seems that something could be wrong with the iFile possibly. If you can provide me the contents of the iFile I might be able to test this in my lab and see if I can get it to work.
sent an email with the details ,redirect to maintenance is not needed we need logic only when both the pools are down route the traffic to point to ifile without any uri redirect.
We need uri redirect for the default pool 1, when pool1 is down and traffic is fwded to pool2 based on the condition . In all these scenarios i need HTTP::redirect.
I’m a bit confused as to what the request is. It might be helpful for you to divide up everything that you want into a numbered list. An example of my confusion, your first if statement says to send traffic to pool1 if it has zero members available. Doing the previous would result in a failed connection because no members are available in pool1. You then check the source of the connection and that pool2 has active members which then sends traffic to pool2 and then checks for URI path “/” and does a redirect to “/testpage/” if “/” is the URI. Then if pool2 has all members down then you return the contents of the ifile “applicationdown.html”.