For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

Kenny_Koulabout's avatar
Kenny_Koulabout
Icon for Nimbostratus rankNimbostratus
Dec 03, 2014

Need help rewriting the middle of a URI

I am unsure of how to rewrite the middle of a uri.

What I am trying to accomplish is this: www.company.com/common/images/sbox/common/images/sbox/any.jpg

and removing the repeating portion of the uri to be:

www.company.com//common/images/sbox/any.jpg

It will be part of a switch and this is what I originally came up with but it does not work.

"/common/images/sbox/common/images/sbox*" { HTTP::redirect http://[HTTP::host]/common/images/sbox/[HTTP::path]}

4 Replies

  • John_Alam_45640's avatar
    John_Alam_45640
    Historic F5 Account

    Try this:

    /common/images/sbox/common/images/sbox*" { HTTP::redirect http://[HTTP::host][string range [HTTP::path] 19 end]}  
    

    or if you want to dynamically eliminate duplicated words:

    set path [regsub -all {\/(\S+)\1+} [HTTP::path] {\1}]
    HTTP::redirect http://[HTTP::host]$path  
    
    • Kenny_Koulabout's avatar
      Kenny_Koulabout
      Icon for Nimbostratus rankNimbostratus
      John, this /common/images/sbox/common/images/sbox*" { HTTP::redirect http://[HTTP::host][string range [HTTP::path] 19 end]} didn't end up working. It would not rewrite the URI at all. It is staying in it's original state.
  • John_Alam_45640's avatar
    John_Alam_45640
    Historic F5 Account

    How are you testing.

    Try this and send the output from the log. (tail /var/log/ltm)

    /common/images/sbox/common/images/sbox*" { 
       set new_uri [string range [HTTP::uri] 19 end]
       log local0. "Old URI: [HTTP::uri]"
       log local0. "New URI: $new_uri"
       HTTP::redirect http://[HTTP::host]$new_uri
    }  
    
  • The systems engineer that was working with me was seeing what uri was being passed using Fiddler. What finally ended up working for me was a modification of another iRule that was implemented before.

    if { ([string tolower [HTTP::uri]] equals "/common/images/sbox/common/images/sbox") or ([string tolower [HTTP::uri]] starts_with "/common/images/sbox/common/images/sbox/")} {
    HTTP::uri "/common/images/sbox/[findstr [HTTP::uri] /common/images/sbox/common/images/sbox/ 39]"
    pool www.company.com-80   
    

    I am still very new to all of this and do not fully understand how the findstr and the string range commands work. Can you explain the difference between your solution and mine is?

    Thanks in advance!