# Problems with a rewrite. Please help

**URL:** <https://community.f5.com/t/problems-with-a-rewrite-please-help/17351>\
**Category:** Technical Forums\
**Tags:** irules, dev, devops, application-delivery\
**Created:** [June 13, 2012, 1:39pm UTC](https://community.f5.com/t/problems-with-a-rewrite-please-help/17351 "2012-06-13T13:39:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Stephenso](https://avatars.discourse-cdn.com/v4/letter/d/ebca7d/32.png) [@David\_Stephenso](https://community.f5.com/u/David_Stephenso)\
**Post date:** [June 13, 2012, 1:39pm UTC](https://community.f5.com/t/problems-with-a-rewrite-please-help/17351/1 "2012-06-13T13:39:25Z")

</div>

Hi, I’ve been asked to write an irule that will intercept anything with a uri that begins with /upload and remove the /upload.

Also, the rule needs to rewrite the host from whatever it is to be the hostname of the server in the pool that it gets served by and to also have :8080 added to it.

[https://images.blah.com/upload/document-delivery/uploadfile](https://images.blah.com/upload/document-delivery/uploadfile)

to be rewritten to

[http://hostname:8080/document-delivery/uploadfile](http://hostname:8080/document-delivery/uploadfile)

So far I have come up with this:

when HTTP\_REQUEST {

set origuri [HTTP::uri]

if { $origuri starts\_with “/upload” } {

HTTP::uri [string range $origuri 7 end]

pool pool1

}

}

which I thought would at least remove the /upload part of the URI but it doesn’t seem to.

Any help is greatly appreciated.

---

<div class="post-metadata">

**Author:** ![hoolio](https://avatars.discourse-cdn.com/v4/letter/h/f6c823/32.png) [@hoolio](https://community.f5.com/u/hoolio)\
**Post date:** [June 13, 2012, 3:24pm UTC](https://community.f5.com/t/problems-with-a-rewrite-please-help/17351/2 "2012-06-13T15:24:08Z")

</div>

Hi David,

Here’s an example which rewrites the host header value based on the selected server IP address:

> **[DevCentral](https://community.f5.com/)**
>
> DevCentral is an online technical community where engineers and practitioners collaborate, share knowledge, and solve problems related to F5 technologies and industry trends.

You could modify that to change the URI as you need to. In pre-v11, the [HTTP::uri] value is cached within the same event. The actual value sent to the pool is updated though. If you want to log the updated value, you can do this in a later HTTP\_REQUEST event:

```tcl
when HTTP_REQUEST {
   log local0. "[IP::client_addr]:[TCP::client_port]: Original request: [HTTP::host][HTTP::uri]"
   if { [HTTP::uri] starts_with "/upload" } {
      HTTP::uri [string range [HTTP::uri] 7 end]
      pool pool1
   }
}
when HTTP_REQUEST priority 501 {
   log local0. "[IP::client_addr]:[TCP::client_port]: Current request: [HTTP::host][HTTP::uri]"
}

```

Aaron
