Forum Discussion
Redirect on host and uri
Having some trouble with this redirect. I am trying to redirect to maint page globally on pool members being down. However, I need to redirect a certain url and a certain URI to a seperate page if they are present. I tried several different rules. My last one here, I split everything out into specifc lines. Maybe I just cannot see the forest through the trees today.
when HTTP_REQUEST {
These requests go to specified maintenance page if conditions are met otherise go to default page
if { ([active_members [LB::server pool]] == 0 && [string tolower [HTTP::host]] starts_with "abc.webserver.com") } {
HTTP::redirect "http://sorrypage.net/default_api.aspx"}
if { [active_members [LB::server pool]] == 0 && [string tolower [http_uri]] starts_with "/identity/issue/oauth2/token"} {
HTTP::redirect "http://sorrypage.net/default_api.aspx"}
elseif { [active_members [LB::server pool]] == 0} {
HTTP::redirect "http://maintenance.cloudapp.net"} }
5 Replies
- nathe
Cirrocumulus
Valentine
How about this?when HTTP_REQUEST { if { [active_members [LB::server pool]] == 0 && [string tolower [HTTP::host]] starts_with "abc.webserver.com" }{ HTTP::redirect "http://sorrypage.net/default_api.aspx" } elseif { [active_members [LB::server pool]] == 0 && [string tolower [http_uri]] starts_with "/identity/issue/oauth2/token"}{ HTTP::redirect "http://sorrypage.net/default_api.aspx" } elseif { [active_members [LB::server pool]] == 0} { HTTP::redirect "http://maintenance.cloudapp.net" } }
Hope this helps,
N - nathe
Cirrocumulus
Valentine - the iRule should have two sets of && as per your example. Uploading has changed this. - Valentine_96813
Nimbostratus
When I try this I get the same result as mine. Everything seems to redirect using the global at the bottom. The host and URI exclusion seem to be ignored or not matched.
- nathe
Cirrocumulus
Saw one mistake in the code so slight adjustment. Also added a log at the beginning just to be sure of what we're seeing:
when HTTP_REQUEST {
log local0. "Host is [HTTP::host], URI is [HTTP::uri]"
if { ([active_members [LB::server pool]] == 0) && ([string tolower [HTTP::host]] starts_with "abc.webserver.com") } {
HTTP::redirect "http://sorrypage.net/default_api.aspx"
} elseif { ([active_members [LB::server pool]] == 0) && ([string tolower [HTTP::uri]] starts_with "/identity/issue/oauth2/token") } {
HTTP::redirect "http://sorrypage.net/default_api.aspx"
} elseif { ([active_members [LB::server pool]] == 0) } {
HTTP::redirect "http://maintenance.cloudapp.net"
}
} - nathe
Cirrocumulus
Did you manage to try this irule?
I tried it in the lab today and it worked. Although I did have to swap around the if statements so URI is checked prior to Host - else it always matched the Host.
Rgds
N
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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
