Forum Discussion

igor_'s avatar
igor_
Icon for Cirrus rankCirrus
Jul 21, 2023

LTM Policy HTTP Rewrite Rule

Hi all,

I am trying to rewrite the part of Path URI using LTM Policy but the problem is when the Path URI gets rewritten the whole URI is rewritten without keeping the rest of the path.

So for example, and I am pasting my exact rule just masked the parts because of information disclosure, when the request is: https://www.mydomain1.com/path1/v2/d/the_rest_of_the_path I want to rewrite /path1/v2/d into /path/app and then add the rest of the path content: https://www.mydomain1.com/path1/v2/d/beta/search?q=test  

into  https://www.mydomain1.com/path/app/beta/search?q=test  

But what I get is: https://www.mydomain1.com/path/app/ and the rest is cut off.

Does anyone have a suggestion using GUI interface without resorting to iRule?

 

Thanks,

Igor

  • igor_ Sadly I'm far familiar with iRules than traffic policies so I'm not sure if you can do this in a traffic policy. What you want to do is a string map rather than a rewrite and the string you want to map is "/path1/v2/d" to "/path/app" which should conver the path as it traverses the F5 VS and is sent to the pool members.

    • JRahm's avatar
      JRahm
      Icon for Admin rankAdmin

      So igor_ , what Paulius is saying here is to use the local traffic policy, but you can use Tcl in it to avoid the separate iRule:

              rewrite_uri_path_partial {
                  actions {
                      0 {
                          http-uri
                          replace
                          value "tcl:[string map {/path1/v2/d/ /path/app/} [HTTP::uri]]"
                      }
                  }
                  conditions {
                      0 {
                          http-uri
                          path
                          starts-with
                          values { /path1/v2/d/ }
                      }
                  }
                  ordinal 1
              }
    • JRahm's avatar
      JRahm
      Icon for Admin rankAdmin

      I haven't used the rewrite profile operationally before, so I'm not sure if it's absolute or relative in what it replaces, but in looking at the config, seems possible on a request if it is a pattern match rather than an absolute path match:

      create the profile, then attach to your virtual server. Your test virtual server of course... 😎