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 u...
May 24, 2006
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.
Also, you are using matches_regex when you don't need to. Since you are just looking for the start of the string, the "starts_with" operator is much more efficient. You should avoid regular expressions unless there is no alternative.
Give this a shot:
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]"
}
You also might need a "string tolower" in there for the HTTP::uri check...
-Joe
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