Forum Discussion

stan_peachey_86's avatar
Mar 04, 2010

iRule: problem modifying uri without a redirect

I'm attempting to do a simple uri modify without a redirect and nothing changes:

 

 

when HTTP_REQUEST {

 

 

if { ([HTTP::uri] starts_with "/aaa/bbb/CCC/") } {

 

HTTP::uri "/aaa/bbb/ZZZ/"

 

}

 

}

 

 

logs show that the uri is not being modified. what am I missing? Thanks

 

 

-stan

3 Replies

  • HTTP::uri is cached, so you won't see the change in the log unless you add another lower priority (higher number) event for the log statement. 500 is the default priority, so anything higher will show the changed uri in a log statement. If you check the tcpdump, it should meet your expectations on the wire. You could add this to your rule to verify in your local logs:

     
     when HTTP_REQUEST priority 550 { 
       log local0. "Updated URI is [HTTP::uri]" 
     } 
     

  • Thanks for the cache priority tip citizen. just to keep this post updated, here is an alternative iRule suggested by f5 for uri modification using variables for the rewrite:

     

     

    when HTTP_REQUEST {

     

    if { [HTTP::uri] starts_with "/test" } {

     

    set old_uri [HTTP::uri]

     

    log local0. "BEFORE: $old_uri"

     

    set new_uri "/index.html"

     

    HTTP::uri $new_uri

     

    log local0. "AFTER: $new_uri"

     

    }

     

    }

     

     

  • While you can be assured the magic is happening without logging, there really isn't any validation in that example. If going this route, might as well not set the variable to conserve cycles. Also, more conservative to send one log statement.

     
     when HTTP_REQUEST { 
       if { [HTTP::uri] starts_with "/test" } { 
         HTTP::uri /index.html 
         log local0. "Original URI: [HTTP::uri], New URI: /index.html" 
       } 
     } 
     

    If you want to handle the case issues, (ie, user1 enters /test, but user2 enters /Test), use the string tolower command.

    HTH...Jason