Forum Discussion
Richard__Harlan
May 24, 2006Historic F5 Account
nested if statements
Working on a simple iRule to redirect traffic from certain uris to our siteunavailable page. The main problem is on certain paged we do not want to redirect to a domain name but to an IP address. We use this logic in other rules and it work find but in this one the if statement is always coming back as true. I was hoping someone could catch what we are missing.
when HTTP_REQUEST {
if { [HTTP::uri] matches_regex "^/servlet/mike" or
[HTTP::uri] matches_regex "^/servlet/chad" } {
if {[string first -nocase "deere" [HTTP::host]]} {
log "deere [HTTP::host]"
redirect to "http://unavailable.deere.com/index.pl?SiteName=unavailable.deere.com"
} else {
log "no deere [HTTP::host]"
redirect to "http://x.x.x.x/index.pl?SiteName=unavailable.com"
}
}
log "fell thru [HTTP::host]"
}
No matter what the [HTTP::host] is it always catches on the if statement even if [HTTP::host] equals an IP address. Thanks
- The "string first" command will return the index of the found string or -1 if it's not found. So valid values or -1 (for not found) and 0 to len-1 if the string is found. If you are converting this to a boolean value for the if condition, then the only thing that would fail would be a value of 0 (or when the string starts with your substring). I don't think this is what you want. I'd specifically check that the return value is != -1.
when HTTP_REQUEST { if { [HTTP::uri] starts_with "/servlet/mike" or [HTTP::uri] starts_with "/servlet/chad" } { if {-1 != [string first -nocase "deere" [HTTP::host]]} { log "deere [HTTP::host]" redirect to "http://unavailable.deere.com/index.pl?SiteName=unavailable.deere.com" } else { log "no deere [HTTP::host]" redirect to "http://x.x.x.x/index.pl?SiteName=unavailable.com" } } log "fell thru [HTTP::host]" }
Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects