Forum Discussion

Richard__Harlan's avatar
Richard__Harlan
Historic F5 Account
Jul 11, 2005

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"

7 Replies

  • unRuleY_95363's avatar
    unRuleY_95363
    Historic F5 Account
    Because 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__Harlan's avatar
    Richard__Harlan
    Historic F5 Account
    I gave that a try and it is still falling through the rule and hitting the default pool. Anything else you can think of? Thanks

     

     

    elseif { [URI::decode [HTTP::uri]] starts_with "/deerecom/farmers+and+ranchers/publications" } {
  • unRuleY_95363's avatar
    unRuleY_95363
    Historic F5 Account
    Did 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.

     

     

    -Joe
  • Richard__Harlan's avatar
    Richard__Harlan
    Historic F5 Account
    I 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.
  • 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=.+" .
  • 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.

     

     

    Aaron