Forum Discussion
Mojdeh_Koushki_
Nimbostratus
Oct 14, 2005iRule Script in Ver 9 is not functioning
hello
here is my problem, i have a set of bigip for bunch of web farm on ver 4.5.10, which i have this iRule for it and it is functioning Very Well...
if (getfield(http_uri, '/', 2) m...
Oct 14, 2005
Mojdeh,
To quote a string you need to use double quotes, not single quotes. The string '/' equates to "'/'" which is not in the URI.
This should work for you:
when HTTP_REQUEST {
if { [string tolower [getfield [HTTP::uri] "/" 2]] == "webapp" } {
HTTP::redirect "https://[HTTP::host][HTTP::uri]"
} else {
pool POOL_HTTP_Vlan70
}
}
Another implementation without using getfield would be to use the starts_with operator. An equivalent rule would be something like this
when HTTP_REQUEST {
if { [string tolower [HTTP::uri]] starts_with "/webapp" } {
HTTP::redirect "https://[HTTP::host][HTTP::uri]
} else {
pool POOL_HTTP_Vlan70
}
}
By doing this you save a few CPU cycles.
In the future, you can make use of the log command to debug your rules. By starting at the inner most statment, it's fairly straight forward with the following code to find out where you problem lied in this rule:
when HTTP_REQUEST {
set uri [HTTP::uri]
set field [getfield $uri '/' 2]
set lower [string tolower $field]
set slash '/'
set field2 [getfield $uri "/" 2]
set lower2 [string tolower $field]
set slash2 "/"
log local0. "URI: $uri"
log local0. "Field: $field"
log local0. "Lower: $lower"
log local0. "slash: $slash"
log local0. "Field2: $field2"
log local0. "Lower2: $lower2"
log local0. "slash2: $slash2"
}
The output will be put in the /var/log/ltm file on the BIG-IP. Of course all those local variables probably aren't a good idea for production, but it allows you to debug and work out the kinks.
-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