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

Cambo_146377's avatar
Cambo_146377
Icon for Nimbostratus rankNimbostratus
Mar 05, 2014

Re-write request to new endpoint and modify query string params

Apologies (to Kevin Stewart) - this is a re-post as I had to delete the first one as I couldn't edit it properly - the editor seems to be buggy. This is a slight revision of my original question.

 

Hello,

 

I want to re-write an external request like this:

 

https://externaldomain.org?param1=value1&param2=value2

 

to an internal request like this

 

http://192.168.2.100/value1/NewEndpoint?param2=value2

 

So one of the params needs to be removed from the query string and used in the new route URI.

 

Totally a newbie - any help is greatly appreciated.

 

Thanks.

 

1 Reply

  • This might be one way to do it:

    when HTTP_REQUEST {
        if { ( [HTTP::path] equals "/" ) and ( [HTTP::query] ne "" ) } {
            HTTP::uri "/[URI::query [HTTP::uri] param1]/NewEndpoint?param2=[URI::query [HTTP::uri] param2]"
        }
    }
    

    The above is dependent on the named params (param1 and param2). If the values can be different and/or you just need to move the first param, another option would be to split the query string into a list.

    when HTTP_REQUEST {
        if { ( [HTTP::path] equals "/" ) and ( [HTTP::query] ne "" ) } {
            set query [split [HTTP::query] "&"]
            HTTP::uri "/[lindex [split [lindex $query 0] "="] 1]/NewEndpoint?[lindex $query 1]"
        }
    }