Forum Discussion
If/Else Redirect Irule Question.
I have an irule that redirects to different pools based on the URI (I have posted it several times). I'm having an issue in that the redirect appears to be looping due to the website making calls to multiple URIs and most of them are not defined (these are things like favicons and page borders, etc...). So instead of going to the redirect the URI should be pointing them to the irule is running again and sending them to a default pool.
How do I get this to stop looping? Is there a way I can stop the irule from processing once it matches and completes an "if/then" condition?
I have included the irule below. Sections with Pool1 and Pool2 are working without issue.
Thanks.
when HTTP_REQUEST {
log local0. "Making URI lowercase."
switch -glob [string tolower [HTTP::uri]] {
"/abc/xyz" -
"/abc/xyz/" -
"/" {
log local0. "Redirecting based on /abc/xyz."
HTTP::respond 301 "Location" "https://myplace.com/abc/xyz/myplace"
}
"/redirect*" {
log local0. "Redirecting based on redirect"
This next section states that if there are more than 0 pool members are active in the Pool1_pool
then the user is redirected there, else they are presented a Maintenance Page.
if { [active_members Pool1_pool] > 0 } {
log local0. "Sending to Pool1_pool."
pool Pool1_pool
} else {
log local0. "Sending to MX Page for Pool1_pool."
HTTP::respond 503 content [ifile get "/external/MaintenancePage_ifile"] noserver "Content-Type" "text/html" "Cache-Control" "no-cache, must-revalidate"
return
}
}
"*/hrp/*" {
log local0. "Redirecting based on hrp."
This next section states that if there are more than 0 pool members are active in the Pool2_pool
then the user is redirected there, else they are presented a Maintenance Page.
if { [active_members Pool2_pool] > 0 } {
log local0. "Sending to Pool2_pool."
pool Pool2_pool
} else {
log local0. "Sending to MX Page for the Pool2_pool."
HTTP::respond 503 content [ifile get "/external/MaintenancePage_ifile"] noserver "Content-Type" "text/html" "Cache-Control" "no-cache, must-revalidate"
return
}
}
default {
log local0. "Redirecting based on default."
This next section states that if there are more than 0 pool members are active in the Pool3_pool
then the user is redirected there, else they are presented a Maintenance Page.
if { [active_members Pool3_pool] > 0 } {
log local0. "Sending to the Pool3_pool."
pool Pool3_pool
} else {
log local0. "Sending to MX Page for the Pool3_pool."
HTTP::respond 503 content [ifile get "/external/MaintenancePage_ifile"] noserver "Content-Type" "text/html" "Cache-Control" "no-cache, must-revalidate"
return
}
}
}
This next section inserts an HttpsIndicatorHeader value of True to prevent Websphere redirect errors.
log local0. "Inserting HttpsIndicatorHeader Value"
HTTP::header insert HttpsIndicatorHeader True
}
- gdoyle
Cirrostratus
I resolved this by adding in the "event disable" in the appropriate redirect field. I also had to manipulate where the
line was. Instead of having it as more of a global action as it pertains to the irule, I added it individually to each "if" statement where it redirected to an active pool (not where it would redirect the the maintenance page).HTTP::header insert HttpsIndicatorHeader True
Thanks, y'all.
See below links for reference: https://devcentral.f5.com/articles/irules-disabling-event-processing https://devcentral.f5.com/questions/stop-processing-irule-s-if-condition-is-met
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