Forum Discussion

Eljay's avatar
Icon for Cirrus rankCirrus
Oct 17, 2023

Remove a specific string in path on request and insert on response

Hi guys,

I have a challenge for you.
I have a policy which will redirect traffic to a different pool/node when the path starts with a specific string. This string must be removed before it is sent to the server.

How can I insert that string at the beginning of the path when the response comes back from the server, so that the paths returned to the client will be correct? 

Request: https://host.xy/strawberry/xxx/yyy ----rewrite towards the server--- > https://host.xy/xxx/yyy
Response paths: /random_path ---rewrite towards the client---> /strawberry/random_path
Next request will then be: https://host.xy/strawberry/random_path
The "strawberry" string is unknown for the server, it is just to let BigIP redirect it to a different pool/node.

The string should of course be inserted only on URLs that are relative to the server or starts with "https://host.xy/".

Is it possible to do this with a stream profile? I can probably do it with an iRule (using HTTP::collect and HTTP::payload), but that will be more complex and harder for my colleagues to understand and maintain (they don't know iRules).

I hope you understand what I am trying to do.

3 Replies

  • Eljay I believe what you are looking for is a string map and the following should do exactly what you described in your example.

    when HTTP_REQUEST priority 500 {
        if {[HTTP::uri] starts_with "/strawberry/"} {
            HTTP::uri [string map {"/strawberry/" "/"}[HTTP::uri]]
            pool pool_web