Forum Discussion
ppphatak_127926
Nimbostratus
Sep 07, 2005findclass function doesnt work
I have a class called "myclass" having two members.
www.test1.com,www.yahoo.com
www.test2.com,www.msn.com
and wish to run this single rule against it.
redirect to getfield(findclass(domain(http_host, 1), myclass), ',', 2)
Idea is it will check the incoming url, and based on that it will pick up 2nd value after comma from the class and then redirect to it. Meaning, if I access using www.test2.com, then it should redirect me to www.msn.com. This doesnt work. Can someone throw light on what could be wrong pl?
Thx.
- Here are the docs for those methods:domain() - Parses and returns up to the specified number of trailing parts of a domain name from the specified expression.findclass() - The findclass() function finds the member of a class that starts with or matches the beginning of that class member. This function returns the value of that class member. This is similar to the one of class identifier, except that the member is not required to be equal; instead, the member is only required to start with the string and returns the entire member value. getfield() - The getfield() function splits a string on a character, and returns the string corresponding to the specific field. The function returns an empty string if the value of does not evaluate into a string, or if the specified value is greater than the number of fields the evaluated was split into. If the specified character or string is not found in the evaluated , then it is treated as one field.
x = domain(http_host,1) y = findclass(x, myclass) z = getfield(y, ',', 2)
x = domain("www.test1.com", 1) // x will now contain "com" since you specified // to return up to 1 trailing part of the domain name.
class myclass { www.test1.com,www.yahoo.com www.test2.com,www.msn.com } redirect to getfield(findclass(http_host, myclass), ',', 2)
class myclass { test1.com,www.yahoo.com test2.com,www.msn.com } redirect to getfield(findclass(domain(http_host, 2), myclass), ',', 2)
- ppphatak_127926
Nimbostratus
I tried - Martin_MachacekHistoric F5 AccountYeah ... I see the problem. There appears to be a bug in the rule evaluator. The findclass function actually matches a class member if it is a substring of the string to match. An example:
class animals { "bee" "beaver" } findclass("beer", animals) returns "bee" findclass("be", animals) returns empty string findclass("bumblebee", animals) returns "bee" findclass("beaverbee", animals) returns "bee"
- unRuleY_95363Historic F5 AccountI'm not sure that's the problem here since that would actually result in a redirect to the wrong place, not the lack of a redirect at all...
- Martin_MachacekHistoric F5 AccountCorrect, and it actually works that way in my tests. I'm using following config:
class hostmap { "test1.mm.lab,fernet.mm.lab" "test2.mm.lab,gin.mm.lab" "test3.mm.lab,rum.mm.lab" } rule mapper { redirect to "http://" + getfield(findclass(http_host, hostmap), ',', 2) + http_uri } virtual 10.66.66.162:80 unit 1 { use rule mapper }
GET /host.html HTTP/1.1 Host: test1.mm.lab
HTTP/1.0 302 Found Location: http:///host.html Connection: close
- ppphatak_127926
Nimbostratus
What is "hotmap"? - ppphatak_127926
Nimbostratus
Sorry. Got it ! - Martin_MachacekHistoric F5 AccountI've already tested configuration almost identical to the one you've posted in the first message in this thread. Results were similar. The only difference was the Location header in the 302 response looked like this:
- ppphatak_127926
Nimbostratus
Sorry, but honestly I am confused now. - Martin_MachacekHistoric F5 AccountI've not tested with IE. As a matter of fact, the browser is irrelevant. All that matters is that BIG-IP actually generates a response. The response is useless because of invalid Location, which is caused by findclass working slightly differently than as documented. So, with "work" I mean that BIG-IP generates the redirect response. I've assumed that your problem was that the redirect (302) response has not been generated at all.
rule redir-map { if(http_host == "www.test1.com") { redirect to "http://www.yahoo.com" } else if(http_host == "www.test2.com") { redirect to "http://www.msn.com" }
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