# URL path rewrite?

**URL:** <https://community.f5.com/t/url-path-rewrite/56311>\
**Category:** Technical Forums\
**Created:** [April 2, 2014, 2:52pm UTC](https://community.f5.com/t/url-path-rewrite/56311 "2014-04-02T14:52:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ST\_Wong](https://avatars.discourse-cdn.com/v4/letter/s/f17d59/32.png) [@ST\_Wong](https://community.f5.com/u/ST_Wong)\
**Post date:** [April 2, 2014, 2:52pm UTC](https://community.f5.com/t/url-path-rewrite/56311/1 "2014-04-02T14:52:51Z")

</div>

Hi all,

Is it possible to perform following redirection using iRules?

[http://www.example.com](http://www.example.com) → node1 and node2 [http://www.example.com/external](http://www.example.com/external) → node3 and node4 (and user sees [http://www.example.com/external/](http://www.example.com/external/)… in the browser URL address bar)

I’m to iRules and sorry for the newbie question.

Thanks a lot. /ST Wong

---

<div class="post-metadata">

**Author:** ![Cory\_50405](https://avatars.discourse-cdn.com/v4/letter/c/f19dbf/32.png) [@Cory\_50405](https://community.f5.com/u/Cory_50405)\
**Post date:** [April 2, 2014, 3:08pm UTC](https://community.f5.com/t/url-path-rewrite/56311/2 "2014-04-02T15:08:21Z")

</div>

Try this, assuming pool node34 is defined with your nodes 3 and 4 as members, and pool node12 is defined with your nodes 1 and 2 as members:

```tcl
when HTTP_REQUEST {
if { [string tolower [HTTP::host]] equals "www.example.com" } {
   if { [string tolower [HTTP::uri]] equals "/external" } {
     pool node34
   }
   else {
    pool node12
   }
}

```

Also keep in mind this isn’t redirection, only pool selection based on the client’s request. No redirection should be needed here.

---

<div class="post-metadata">

**Author:** ![ST\_Wong](https://avatars.discourse-cdn.com/v4/letter/s/f17d59/32.png) [@ST\_Wong](https://community.f5.com/u/ST_Wong)\
**Post date:** [April 3, 2014, 4:13am UTC](https://community.f5.com/t/url-path-rewrite/56311/3 "2014-04-03T04:13:53Z")

</div>

Sorry that I didn’t make the question accurate enough.

[http://www.example.com/external](http://www.example.com/external) → node3 and node4 (and user sees [http://www.example.com/external/](http://www.example.com/external/)… in the browser URL address bar)

In this case, node3/node4 don’t know the uri /external/. I’ve to strip the /external/ part and pass the rest of uri to node3 and node4, then add it back in response to client. Is it possible? Thanks a lot.

---

<div class="post-metadata">

**Author:** ![Cory\_50405](https://avatars.discourse-cdn.com/v4/letter/c/f19dbf/32.png) [@Cory\_50405](https://community.f5.com/u/Cory_50405)\
**Post date:** [April 3, 2014, 1:03pm UTC](https://community.f5.com/t/url-path-rewrite/56311/4 "2014-04-03T13:03:24Z")

</div>

Sure, just a simple change necessary to hide the /external from the nodes:

```tcl
when HTTP_REQUEST {
if { [string tolower [HTTP::host]] equals "www.example.com" } {
   if { [string tolower [HTTP::uri]] equals "/external" } {
     http::uri "/"
     pool node34
   }
   else {
    pool node12
   }
}

```

---

<div class="post-metadata">

**Author:** ![ST\_Wong](https://avatars.discourse-cdn.com/v4/letter/s/f17d59/32.png) [@ST\_Wong](https://community.f5.com/u/ST_Wong)\
**Post date:** [April 4, 2014, 1:10am UTC](https://community.f5.com/t/url-path-rewrite/56311/5 "2014-04-04T01:10:56Z")

</div>

Thanks, but seems I also have to rewrite the uri in HTTP response so that user’s browser will see [http://www.example.com/external/](http://www.example.com/external/)… no matter what content is returned. I tried to do following but seems didn’t work.

when HTTP\_RESPONSE {

STREAM::disable if {[HTTP::header value Content-Type] contains “text”}{ STREAM::expression {@www.example.com/@www.example.com/external/@} STREAM::enable } }

Thanks.
