# URI Rewrite when sending the packet to Backend

**URL:** <https://community.f5.com/t/uri-rewrite-when-sending-the-packet-to-backend/48104>\
**Category:** Technical Forums\
**Tags:** irules, big-ip, application-delivery\
**Created:** [December 16, 2019, 5:00pm UTC](https://community.f5.com/t/uri-rewrite-when-sending-the-packet-to-backend/48104 "2019-12-16T17:00:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Puneet\_SETH](https://avatars.discourse-cdn.com/v4/letter/p/e56c9b/32.png) [@Puneet\_SETH](https://community.f5.com/u/Puneet_SETH)\
**Post date:** [December 16, 2019, 5:00pm UTC](https://community.f5.com/t/uri-rewrite-when-sending-the-packet-to-backend/48104/1 "2019-12-16T17:00:34Z")

</div>

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](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](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=

}

---

<div class="post-metadata">

**Author:** ![Enes\_Afsin\_Al](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/enes_afsin_al/32/15359_2.png) [@Enes\_Afsin\_Al](https://community.f5.com/u/Enes_Afsin_Al)\
**Post date:** [December 16, 2019, 6:23pm UTC](https://community.f5.com/t/uri-rewrite-when-sending-the-packet-to-backend/48104/2 "2019-12-16T18:23:24Z")

</div>

Hi,

for request “[http://1.1.1.1/test/abc?param=1234567890](http://1.1.1.1/test/abc?param=1234567890)”

```tcl
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](http://1.1.1.1/test/abc?param=1234567890)

_Redirect:_ [https://2.2.2.2/test/abc2?param=1234567890](https://2.2.2.2/test/abc2?param=1234567890)

```tcl
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]"
	}
}

```

---

<div class="post-metadata">

**Author:** ![Puneet\_SETH](https://avatars.discourse-cdn.com/v4/letter/p/e56c9b/32.png) [@Puneet\_SETH](https://community.f5.com/u/Puneet_SETH)\
**Post date:** [December 16, 2019, 6:47pm UTC](https://community.f5.com/t/uri-rewrite-when-sending-the-packet-to-backend/48104/3 "2019-12-16T18:47:11Z")

</div>

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.
