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”} }

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

Valentine - the iRule should have two sets of && as per your example. Uploading has changed this.

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.

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”

}

}

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