Forum Discussion

Shawn_Parkerso1's avatar
Shawn_Parkerso1
Icon for Nimbostratus rankNimbostratus
Apr 18, 2018

URL Rewrite using local traffic policy

I am looking to use a local traffic policy instead of a iRule (if possible). We want to rewrite the URI portion of incoming requests as they are presented to the inside web host.

 

Outside: https://www.domain.com/something/prod/something/something Inside: https://www.domain.com/something/something

 

I see the action when creating a policy to REPLACE a portion of the URI. I set it to match "/prod" and replace "" blank field. I also tried to match "/something/prod" and replace with "/something". Neither option seems to work. Is this the correct way to handle this? What is the best way to see how it is getting rewritten if you do not have direct access to web server?

 

Thanks!

 

3 Replies

  • So long as "/PROD/" does not appear anywhere else in the URI, you should be able to use something like below. This assumes the URI is not case sensitive, and that /PROD/ is the same as /prod/ or /Prod/.

    when HTTP_REQUEST {
        if { [string tolower [HTTP::uri]] contains "/prod/" } {
            HTTP::uri [string map { "/prod/" "/" } [HTTP::uri]]
        }
    }
    

    I ran a modest test on my BIG-IP system but await results in your environment.

  • It's a bit hard to determine which "somethings" you want to keep and which "somethings" you want to replace. Could you rephrase your example using unique qualifiers in each position? Or are the "somethings" always the same?

     

    For example:

     

    Outside: https://www.domain.com/something1/prod/something2/something3... Inside: https://www.domain.com/something1/something2/something3...

     

    Depending on what you want to keep/replace and how difficult it is to parse, you may need to use an iRule instead of a Local Traffic Policy. LT policies are limited to a single Tcl line in the "replace with" string whereas with an iRule, you can manipulate the string in a much more granular fashion. That's not to say it can't be done with a policy but additional clarification is in order. Perhaps you can post what you have for your iRule already. That may provide enough information.