URI Rewrite when sending the packet to Backend

Hi All,

I’m working on this requirement to rewrite the URI path in the HTTP Request, just the URI path and not the query portion.

E.g.

Incoming request to

http://1.1.1.1/test/abc?param=1234567890

should be translate to when sending to backend.

https://2.2.2.2/test/abc1?param=1234567890

I’ve tried few iterations but none have worked for me so far.

Sample1

when HTTP_REQUEST {

if { [HTTP::uri] starts_with “/abc1?/” } {

HTTP::uri [string map {“/abc1?/” “/abc2?/”} [HTTP::uri]]

}

}

Sample2

when HTTP_REQUEST {

if {[HTTP::uri] contains “test/abc?param=” } {

set newURI [string map {“test/abc?param=” “”} [HTTP::uri]]

HTTP::uri /test/abc1?param=

}

Hi,

for request “http://1.1.1.1/test/abc?param=1234567890”

host  : 1.1.1.1
uri   : /test/abc?param=1234567890
path  : /test/abc
query : param=1234567890

If you want to change the host, you can use HTTP::redirect

Sample

Request: http://1.1.1.1/test/abc?param=1234567890

Redirect: https://2.2.2.2/test/abc2?param=1234567890

when HTTP_REQUEST {
	if { [HTTP::path] equals "/test/abc" } {
		set newUri [string map {"abc" "abc1"} [HTTP::path]]
		HTTP::redirect "https://2.2.2.2$newUri?[HTTP::query]"
	}
}

Hi,

Here 1.1.1.1 is the VIP and 2.2.2.2 is the backend server.

In original case Host header will be name as it is.