Forum Discussion
Redirecting to an external site when the internal site is down
- Jun 06, 2023
John_Adams It seems like we cannot use a variable that has been created in that section of code. You can try the following to see if this works for you.
when HTTP_REQUEST priority 500 { if { [active_members [LB::server pool]] == 0 } { HTTP::respond 307 content { <html> <head> <title>Apology Page</title> </head> <body> We are sorry, but the site you are looking for is temporarily out of service<br> If you feel you have reached this page in error, please try again. </body> </html> } } }
Hi,
I see that first video shows the use of HTTP::respond instead of HTTP::fallback! That's perfect, because the request is to return a 307, and it appears HTTP::fallback only returns a 302.
Thanks,
John A
John_Adams Typically this is achieved by using two pieces of configuration together.
1. The pool associated to the virtual server in question will have a health monitor for that site and if the response from the pool members is something other than what you define in the receive string then the pool member/s is/are considered down making the entire virtual server go down if the entire pool is down.
2. When the pool is completely down or the iRule defined criteria is met, such as less than 2 pool members of the over all pool members are available then you issue the redirect otherwise you just forward traffic to the pool and let load balancing occur.
The following is an example iRule of how to perform this function with an example website. If you needed to narrow this down to a specific site and associate pool you could add in the additional matching criteria.
when CLIENT_ACCEPTED {
set DEFAULT_POOL [LB::server pool]
}
when HTTP_REQUEST {
if { [active_members [${DEFAULT_POOL}]] == 0 } {
HTTP::respond 307 Temporary Redirect "http://www.example.com/"
}
}
- John_AdamsJun 06, 2023Altostratus
Hi, Paulius,
I've tried to implement this more or less as is:
when CLIENT_ACCEPTED {
set DEFAULT_POOL [LB::server pool]
}
when HTTP_REQUEST {
if { [active_members [${DEFAULT_POOL}]] == 0 } {
HTTP::respond 307 content {
<html>
<head>
<title>Apology Page</title>
</head>
<body>
We are sorry, but the site you are looking for is temporarily out of service<br>
If you feel you have reached this page in error, please try again.
</body>
</html>
}
}}
and I am getting an interesting error:
tmm1[12440]: 01220001:3: TCL error: /Common/_ualr_hostdown_307 <HTTP_REQUEST> - invalid command name "/Common/<app name>/<pool name>" while executing "${DEFAULT_POOL}"
I'm also getting it when I switch to the "Temporary Redirect <URL>" code you presented. Any thoughts?
Thanks,John A
- PauliusJun 06, 2023MVP
John_Adams It seems like we cannot use a variable that has been created in that section of code. You can try the following to see if this works for you.
when HTTP_REQUEST priority 500 { if { [active_members [LB::server pool]] == 0 } { HTTP::respond 307 content { <html> <head> <title>Apology Page</title> </head> <body> We are sorry, but the site you are looking for is temporarily out of service<br> If you feel you have reached this page in error, please try again. </body> </html> } } }
- John_AdamsJun 06, 2023Altostratus
Paulius, I'm now getting no errors and the apology text in Safari, Firefox, and Chrome, which is clear progress and fulfills my specific task.
One oddity: When I tried the "Temporary Redirect <URL>" code you offered, I get no errors and blank screens with all browsers. It's throwing up that apology message that I've been asked to do, but I'm still curious about the other syntax and why it's not working. It seems very straightforward and I don't believe I have any typos.
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