Forum Discussion
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_45640Historic 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
Nimbostratus
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_45640Historic 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 } - Kenny_Koulabout
Nimbostratus
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-80I 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!
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* 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