Forum Discussion
Richard__Harlan
Jul 11, 2005Historic F5 Account
HTTP::uri regex
Haveing a little problem matching a uri in my rule. When a user comes in useing the the following url http://www.deere.com/deerecom/farmers+and+ranchers/publications we want them redirected to redirect to http://www.deere.com/en_US/compinfo/publications/john_deere_publishing/index.html
below is a snip of the rule that does the redirect for the above link. Any help would be great.
elseif { [HTTP::uri] matches_regex "^/deerecom/farmers+and+ranchers/publications"} {
redirect to "http://www.deere.com/en_US/compinfo/publications/john_deere_publishing/index.html"
- unRuleY_95363Historic F5 AccountBecause the uri has some special characters, you may want to use "[URI::decode [HTTP::uri]]" instead of just "[HTTP::uri]". This will make sure that any "%2b" strings are converted into '+' before performing the regex match. Also, the + character is a regex special character, so you may want to escape it with \ ('+' means match the preceding character one or more times). As you are not really doing a regular expression but simply a character match, you may alternatively want to simply use "starts_with" as in:
elseif { [URI::decode [HTTP::uri]] starts_with "/deerecom/farmers+and+ranchers/publications" } { ...
- Richard__HarlanHistoric F5 AccountI gave that a try and it is still falling through the rule and hitting the default pool. Anything else you can think of? Thanks
- unRuleY_95363Historic F5 AccountDid you try logging the result of [URI::decode [HTTP::uri]] to make sure it's what you think it is?
- You might try logging the uri to see what's coming in and make sure it's identical to your starts_with statement. Odds are there is something amiss with those '+' characters.
- Richard__HarlanHistoric F5 AccountI did the logging and it was comming back at /deerecom/farmers and ranchers/publications, I took out the + and the rule work fine. Thanks you guys are great.
- John_Hilgart
Nimbostratus
In my case I had a uri containing "?" which I needed to match, as in this Lotus SameTime path: /stconf.nsf/RepeatList?OpenView&groupid=... What I found through dumb luck and falling back on scripts i have written in PERL is that a double-escape was required to match the "?", as in this regex: "^/stconf\.nsf/RepeatList\\?OpenView\&groupid=.+" . - hoolio
Cirrostratus
It would be better to avoid using a regex, as unruley and joe alluded to in this post. And you can be more precise if you check the HTTP::path and/or HTTP::query values instead of HTTP::uri.
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