Forum Discussion
Ian_Amos_37833
Nimbostratus
Apr 27, 2007Using [HTTP::hostname] & [HTTP::uri]..
Afternoon all,
there is probably a really easy solution for this, but i've not had any F5 training, and have run out of ideas..
To try and explain the situation;
there is a website www.example.com
there is also a UAT copy of the site uat.example.com
there is static content ..com/static/
and databases etc ..com/data/
each of the above are in their own Pools, but are represented by the same Public IP and virtual server.
So far I have an iRule to say
when HTTP_REQUEST {
if { ([HTTP::host] starts_with "uat") } {
HTTP::respond 200 content "<...test...>"
}
}
which works when I go to uat.example.com
How can I incorporate an "AND" statement in the iRule? i.e if HTTP::host starts_with "uat" AND HTTP::uri starts_with "/static/" etc.
I've tried using & but that doesn't work.. what am I doing wrong??
Thanks in advance for your help!
5 Replies
- hoolio
Cirrostratus
"&" is for bitwise operations. You can use "&&" for logical ANDing. Or you can just use "and"!
Here's a reference:
http://tmml.sourceforge.net/doc/tcl/expr.html
Here's an example:if {[HTTP::host] starts_with "uat" && [HTTP::uri] starts_with "/static/"}{
This is equivalent to "and":if {[HTTP::host] starts_with "uat" and [HTTP::uri] starts_with "/static/"}{
Aaron - Ian_Amos_37833
Nimbostratus
Thanks for the help! i'm sure I tried 'and' but think I had ()'s around each arguement, which it doesn't like..
My next problem is with 'elseif'
I'm using:
when HTTP_REQUEST {
if {[HTTP::host] starts_with "uat" && [HTTP::uri] starts_with "/static/"}{
HTTP::respond <..etc..>
} elseif { [HTTP::host] starts_with "uat" && [HTTP::uri] starts_with "/data/"}{
HTTP::respond <..different etc..>
}
}
I know i've now got the '&&' bit working, as with just the one IF statement, everything is fine. But I can't get anything after the 'elseif' to work..
Thanks again for your help! - hoolio
Cirrostratus
The format you have posted should work. I tested the following and both the if and elseif actions worked:when HTTP_REQUEST { if {[HTTP::host] starts_with "if" && [HTTP::uri] starts_with "/if"}{ HTTP::respond 200 content "matched if" } elseif { [HTTP::host] starts_with "elseif" && [HTTP::uri] starts_with "/elseif"}{ HTTP::respond 200 content "matched elseif" } }
Can you check the /var/log/ltm log file for errors when you test your rule?
Also, you should be able to wrap conditions in ()'s. You would get an error if you used []'s to wrap the conditions though.
Aaron - Ian_Amos_37833
Nimbostratus
Posted By hoolio on 04/30/2007 2:41 AM
Can you check the /var/log/ltm log file for errors when you test your rule?
Aaron
I can see this in the logs:TCL error: Rule UAT-test HTTP_REQUEST - Operation not supported. Multiple redirect/respond invocations not allowed line 2 invoked from within HTTP::respond 200 content htmlheadtitleUAT test1/title/headbodydiv align=centertable border=0 width=60 id=table1trtdauat /...
Any suggestions?
What could I use as a "and if none of the above if statements are matched, ignore the whole rule"?
Thanks again - hoolio
Cirrostratus
I didn't get any errors. I think the issue might be escaping for your response content. If you change the response content to "test", do you still get the TCL error? If not, you'll need to escape the metacharacters "[", "]" and quotes, in the HTML code of your response with backslashes (\).
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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