# uri and pool redirection

**URL:** <https://community.f5.com/t/uri-and-pool-redirection/8065>\
**Category:** Technical Forums\
**Tags:** dev, irules, devops, application-delivery\
**Created:** [March 11, 2010, 6:54pm UTC](https://community.f5.com/t/uri-and-pool-redirection/8065 "2010-03-11T18:54:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Robert\_11](https://avatars.discourse-cdn.com/v4/letter/d/ecae2f/32.png) [@David\_Robert\_11](https://community.f5.com/u/David_Robert_11)\
**Post date:** [March 11, 2010, 6:54pm UTC](https://community.f5.com/t/uri-and-pool-redirection/8065/1 "2010-03-11T18:54:12Z")

</div>

Hi,

I think there may be an easy way to do this, I can get some of it to work, but not all of it.

We have a need to redirect traffic to a different pool, based off of the uri. so.

http:\\www.xyz.com\Site1 goes to Pool1, however, if this uri comes in http:\\www.xyz.com\Site2, it should get redirected to http:\\www2.xyz.com\Site2 and go to Pool2, but all other traffic should stay with http:\\www.xyz.com\ and with Pool1

Any ideas how this may work?

---

<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:** [March 11, 2010, 8:15pm UTC](https://community.f5.com/t/uri-and-pool-redirection/8065/2 "2010-03-11T20:15:36Z")

</div>

Hi David,

So you basically want [www.xyz.com/site2](http://www.xyz.com/site2) requests to be redirected to [www2.xyz.com/site2](http://www2.xyz.com/site2), [www2.xyz.com/site2](http://www2.xyz.com/site2) requests to go to pool2 and all other requests to go to pool1? If so, can you try this?

```tcl
when HTTP_REQUEST { 
  
    log local0. "[IP::client_addr]:[TCP::client_port]: [HTTP::method] request to [HTTP::host][HTTP::uri]" 
  
     Check the requested host header 
    switch [string tolower [HTTP::host]] { 
  
       "www.xyz.com" { 
           Request was for www.xyz.com. Check if the URI starts with /site2 
          if {[HTTP::path] starts_with "/site2"}{ 
              Redirect client to www2.xyz.com with the original URI 
             log local0. "[IP::client_addr]:[TCP::client_port]: www.xyz.com/site2 request, redirecting." 
             HTTP::redirect "http://www2.xyz.com[HTTP::uri]" 
          } else { 
              Not a /site2 URI, so use pool1 
             log local0. "[IP::client_addr]:[TCP::client_port]: www.xyz.com non-site2 request, using pool1." 
             pool pool1 
          } 
       } 
       "www2.xyz.com" { 
           Request was for www2.xyz.com. Use pool2 
          log local0. "[IP::client_addr]:[TCP::client_port]: www2.xyz.com request, using pool2." 
          pool pool2 
       } 
       default { 
           Take some default action for other hosts? 
          log local0. "[IP::client_addr]:[TCP::client_port]: No host match." 
       } 
    } 
 }

```

Aaron

---

<div class="post-metadata">

**Author:** ![The\_Bhattman](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/the_bhattman/32/13958_2.png) [@The\_Bhattman](https://community.f5.com/u/The_Bhattman)\
**Post date:** [March 11, 2010, 8:16pm UTC](https://community.f5.com/t/uri-and-pool-redirection/8065/3 "2010-03-11T20:16:11Z")

</div>

Hi David,

I am assuming that [www2.xyz.com](http://www2.xyz.com) and [www.xyz.com](http://www.xyz.com) are pointing to the same VIP.

Based on this you can do the following

```tcl
when HTTP_REQUEST { 
    switch -glob [string tolower [HTTP::uri]] { 
    "/site2" {pool pool2 } 
    default {pool pool1 } 
    } 
 }

```

or if you assign pool1 as the default pool then you can also right it as

```tcl
when HTTP_REQUEST { 
    switch -glob [string tolower [HTTP::uri]] { 
    "/site2" {pool pool2 } 
    } 
 }

```

--------------

if [http://www2.xyz.com/site2](http://www2.xyz.com/site2) is pointing a seperate vip then the iRule would look something like the following:

```tcl
when HTTP_REQUEST { 
    switch -glob [string tolower [HTTP::uri]] { 
    "/site2" {HTTP::redirect "http:\\www2.xyz.com\Site2" } 
    default {pool pool1 } 
    } 
 }

```

or if you assign pool1 as the default pool then you can also right it as

```tcl
when HTTP_REQUEST { 
    switch -glob [string tolower [HTTP::uri]] { 
    "/site2" {HTTP::redirect "http:\\www2.xyz.com\Site2" } 
    } 
 }

```

I hope this helps

Bhattman

---

<div class="post-metadata">

**Author:** ![David\_Robert\_11](https://avatars.discourse-cdn.com/v4/letter/d/ecae2f/32.png) [@David\_Robert\_11](https://community.f5.com/u/David_Robert_11)\
**Post date:** [March 11, 2010, 8:27pm UTC](https://community.f5.com/t/uri-and-pool-redirection/8065/4 "2010-03-11T20:27:02Z")

</div>

Hi,

Thank you for the reply’s.

It started out as a simple redirect that almost works. If user went to http:\\www.xyz.com\anysite they would get the default web pool and everything is good. However, they want to use the same name, but a different site is to go to a different pool. So, http:\\www.xyz.com\diffsite would redirect to a different pool via an irule. That worked. However, some code in the application would contain references to the default site “http:\\www.xyz.com\” and fail since the default site isn’t serving up the same app, (but they are the same app, just differnent versions). So, the thought was, have the second server/pool serve up [www2.xzy.com](http://www2.xzy.com), and try and have all the traffic get routed to that new pool.

So, I think I’m trying to do two things, hit the default site and based of off \sitename do a redirect to a different host name, which is then matched to a different pool. I am hoping the logic in this I-rule will work to allow that?
