Forum Discussion
Moe_Jartin
Cirrus
Jan 22, 2010How to match just / uri????
I have the following irule:
when HTTP_REQUEST {
switch -glob [string tolower [HTTP::uri]] {
/services* {
pool pool_beta-dev.blah.org_SERVICES
}
/access* -
/auth* {
pool pool_beta-dev.blah.org_AUTH
}
/home* -
/shared* {
pool pool_beta-dev.blah.org_SHARED
}
/ -
/main* -
/member* -
/legal* -
/manual* -
/platform* -
/resources* -
/search* {
pool pool_beta-dev.blah.org_SEARCH
}
/notebook* {
pool pool_beta-dev.blah.org_NOTEBOOK
}
/error* {
pool pool_beta-dev.blah.org_ERROR
}
/sys-policy* {
pool pool_beta-dev.blah.org_POLICY
}
default {
HTTP::redirect http://beta-dev.blah.org/error/ui?code=404
}
}
}
Notice the match for just forward slash (/) going to the SEARCH pool. I can not get any request for just / to go to that pool. They just hit the default at the bottom and get redirected to the error page. Is there some secret to matchig just forward slash? Strange thing is, I have a nearly identical irule on another LTM and it matches on just / fine. HELP!!???!!!
10 Replies
- The_Bhattman
Nimbostratus
Hi Joe,. . . "" - "/main*" - "/member*" - "/legal*" - "/manual*" - "/platform*" - "/resources*" - "/search*" { pool pool_beta-dev.blah.org_SEARCH } . . .
- Moe_Jartin
Cirrus
Doesn't that make it act like an equals? effectively removing my wildcards?? - Moe_Jartin
Cirrus
I tried it with quotes and stil the same behavior. Why is it NOT matching????? - hoolio
Cirrostratus
I'm not sure quotes will make a difference for switch cases: - Moe_Jartin
Cirrus
So after turning on some logging and looking at the HTTP headers in the browser i discovered that it actually WAS matching on just the "/" but then the server was redirecting with some params so it was trying to go to /?lang=eng, which of course was NOT being matched by just /. So I had to add another match string for "/?*". Of course the ? is a regex special character so I had to escape it, so then it looked like "/\?*" but that wasn't matching for some reason either. After a bit of digging I found that I had to double escape the ? for some reason????? So the final match strings looks like: - hoolio
Cirrostratus
It should work with a single escaping backslash:when RULE_INIT { set slash_string /\?param=value log local0. "$slash_string: $slash_string" switch -glob $slash_string { /\?* { log local0. "matched 1" } default { log local0. "no match" } } }
- Moe_Jartin
Cirrus
Aaron, - hoolio
Cirrostratus
HTTP::uri returns the full URI (/path/to/file.ext?param=value) and HTTP::path returns just the path (/path/to/file.ext). For a URI of /?param=value, HTTP::path would return just /. - Moe_Jartin
Cirrus
I have TONS of "URI Switching" iRules in my LTMs. Would HTTP::path be quicker or at least less resource-intensive? Thanks Again. - hoolio
Cirrostratus
I think you'd need to do some testing to find that out for your particular rules/applications. You can use the timing command to check the average CPU cycles per event: http://devcentral.f5.com/wiki/default.aspx/iRules/timing
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