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
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
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… ???
koushki,
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
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
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
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
Joe
i add your suggestion to my iRule … try it now
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
It’s fairly obvious from the above log, but getfield doesn’t behave in what I would call an intuitive manner. Since the URI path begins with a slash, the first path component is really field 2. So, using getfield on a URI is /two/three/four/five. The first field is always empty. Is that what you were expecting?
As you can see from the trace, Field2 which comes from the getfield command with the slash in double quotes is getting set correctly.
Oct 14 14:23:07 tmm tmm[648]: Rule redirect2 : URI: /webnav/navapp1.asp?association_link=lncust1_hunt&brand_cd=huntxx00
Oct 14 14:23:07 tmm tmm[648]: Rule redirect2 : Field:
Oct 14 14:23:07 tmm tmm[648]: Rule redirect2 : Lower:
Oct 14 14:23:07 tmm tmm[648]: Rule redirect2 : slash: ‘/’
Oct 14 14:23:07 tmm tmm[648]: Rule redirect2 : Field2: webnav
Oct 14 14:23:07 tmm tmm[648]: Rule redirect2 : Lower2:
Oct 14 14:23:07 tmm tmm[648]: Rule redirect2 : slash2: /
Oct 14 14:23:07 tmm tmm[648]: Rule redirect2 : Didn’t find match for webapp!
The the blatant item that sticks out is why you are searching for the string “webapp” when all the uri’s being passed in start with “/webnav”?
The Rule is working correctly because the first element past the first slash does not equal “webapp”.
Also, I would recommend using my “starts_with” example instead of the getfield. getfield would be good if you had to do something with that string after you extracted it but it’s overkill for this situation.
when HTTP_REQUEST {
if { [string tolower [HTTP::uri]] starts_with "/webnav" } {
HTTP::redirect "https://[HTTP::host][HTTP::uri]
} else {
pool POOL_HTTP_Vlan70
}
}
-Joe
Either use an elseif
when HTTP_REQUEST {
set uri [string tolower [HTTP::uri]]
if { $uri starts_with "/webnav" } {
HTTP::redirect "https://[HTTP::host][HTTP::uri]
} elseif { $uri starts_with "/webapp" } {
HTTP::redirect "https://[HTTP::host][HTTP::uri]
} else {
pool POOL_HTTP_Vlan70
}
}
or you could combine them with two expressions or’ed together.
when HTTP_REQUEST {
set uri [string tolower [HTTP::uri]]
if { ($uri starts_with "/webnav") or ($uri starts_with "/webapp") } {
HTTP::redirect "https://[HTTP::host][HTTP::uri]
} else {
pool POOL_HTTP_Vlan70
}
}
Notice that I assigned the lower cased uri to a variable so the tolower wouldn’t have to be processed twice.
-Joe
Just make sure you comment out (using “”) the log statements once you’ve got all the kinks worked out. No need for that extra overhead if you don’t need it.
-Joe
Joe
i re edit the script to capture the activity to log , but when i apply the iRule, and when i hit the website … it is just freez there … do you know why?
thanks
koushki,
We’d have to see the rule that you’re trying to implement before we were able to comment on what might be wrong.
It was obviously working before with the logging lines that Joe recommended, so something must have changed if it’s now hanging.
Thanks,
-Colin
well original problem was … it was not working when we apply iRule … so originally iRule did not working so Joe’s adding line it was just for debug
i have to ask my original question again :
i have this iRule, working in version 4.x , what would be it equal on ver 9.x ?
if (getfield(http_uri, ‘/’, 2) matches_regex “[Ww][Ee][Bb][Aa][Pp][Pp]”) {
redirect to “https://%h/%u”
}
else {
use pool WebApp-50
}
The code for the rule that you’re asking about has been well documented in this thread. Joe provided you a solution, and you confirmed that this solution was working for you.
If it is no longer working, then something in that code must have changed.
My recommendation would be to re-copy the code provided to you already, and start from there, as that is known-good code.
There is no need to re-state the original quesiton, as it has already been clearly answered.
-Colin