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) matches_regex "[Ww][Ee][Bb][Aa][Pp][Pp]") {
redirect to "https://%h/%u"
}
else {
use pool WebApp-50
}
and now we are upgrading to version 9 and compatable iRule for version 9 is COMPILING but NOT FUNCTIONING ...
here is the script...
when HTTP_REQUEST {
if { [string tolower [getfield [HTTP::uri] '/' 2]] == "webapp" } {
HTTP::redirect "https://[HTTP::host][HTTP::uri]"
} else {
pool POOL_HTTP_Vlan70
}
}could you please tell me WHY?
thanks alot
Mojdeh
51 Replies
- 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 thiswhen 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 - Mojdeh_Koushki_
Nimbostratus
well, Joe, when i am changing it to Double quote , then it ois not even can hit the page ....
it looks beter with single quote.... ?!?!? - Colin_Walker_12Historic F5 Accountkoushki,
Could you please re-post the current rule you're using?
When you say that you can't get to the page...what's happening, is it simply erroring out, or redirecting you elsewhere, or not redirecting you at all?
I'd also suggest switching from using "==" to using "eq" when comparing the uri string.
Thanks,
-Colin - Mojdeh_Koushki_
Nimbostratus
Coline,
here what i have in ver 4:
if (getfield(http_uri, '/', 2) matches_regex "[Ww][Ee][Bb][Aa][Pp][Pp]") {
redirect to "https://%h/%u"
}
else {
use pool WebApp-50
}
and i would like to have equvalant of this rule for Version 9 - Mojdeh_Koushki_
Nimbostratus
equvelent in ver 9 which i am running now is this :
when HTTP_REQUEST {
if { [string tolower [getfield [HTTP::uri] '/' 2]] == "webapp" } {
HTTP::redirect "https://[HTTP::host][HTTP::uri]"
} else {
pool POOL_HTTP_Vlan70
}
}
based on the Joe's suggestion, i changed '/' to "/" then i do not even get to my " apply" page which means use https conncetion
i am changing == to eq as you request now - Mojdeh_Koushki_
Nimbostratus
Colin,
no luck!
if you give me your IP i can open up the you on the firewall and you can test it and see
i have a website http://stagemed.teri.org, when you go to the website, then there is an option to " Apply" for loan, when you click in that page, then your url will change to https://stagemed.teri.org/webapp/........ then you can apply for loan or check your status ...
all these web servers are behing Big IP and we are using iRule to protect users when they are in https mode, so if user, change https://stagemed.teri.org/webapp/.... to http://stagemed.teri.org/webapp/.... then iRule should force user to use httpS://stagemed.teri.org/webapp/.... which in version 9 , iRule is not functioning
MK - Did you try adding the logging statements I suggested. I verified my rule works with a uri of http://hostname/WebApp (or any upper-lower case version of WebApp).
If you could log the original [HTTP::uri] and put log statements in each of the conditions that would help diagnose what the issue is.
Unfortunately, we can't do much without more details.
Try this rule and send post the output from the /var/log/ltm file.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" if { [string tolower [getfield [HTTP::uri] "/" 2]] equals "webapp" } { log local0. "Found match for webapp!" HTTP::redirect "https://[HTTP::host][HTTP::uri]" } else { log local0. "Didn't find match for webapp!" pool POOL_HTTP_Vlan70 } }
-Joe - Mojdeh_Koushki_
Nimbostratus
Joe
i add your suggestion to my iRule ... try it now - Mojdeh_Koushki_
Nimbostratus
Joe
when i am using " insted of ' for if { [string tolower [getfield [HTTP::uri] '/' 2]] equals "webapp" } {
log local0. "Found match for webapp!"
i do not even hit the " apply " page ... i think ' is the right symbole
when i am using " , page is just stay there ?!?!? noaction - Please post the log output here. I tested things with using single quotes and the getfield command didn't return any string. I'd be interested in seeing if that's not the same for you. Only the log output will tell...
-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
