# Pool Selection Based on URI and URL Modification

**URL:** <https://community.f5.com/t/pool-selection-based-on-uri-and-url-modification/46377>\
**Category:** Technical Forums\
**Tags:** irules, devops, redirection, application-delivery\
**Created:** [July 1, 2015, 1:43pm UTC](https://community.f5.com/t/pool-selection-based-on-uri-and-url-modification/46377 "2015-07-01T13:43:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Techitect](https://avatars.discourse-cdn.com/v4/letter/t/c6cbf5/32.png) [@Techitect](https://community.f5.com/u/Techitect)\
**Post date:** [July 1, 2015, 1:43pm UTC](https://community.f5.com/t/pool-selection-based-on-uri-and-url-modification/46377/1 "2015-07-01T13:43:41Z")

</div>

I’m trying to write an iRule that will redirect traffic to different pools based on URI, as well as altering the URL to remove the URI after the traffic is redirected to the correct pool. I think I have the initial pool redirect figured out, but I can’t figure out how to do that AND THEN shorten the URL. Here are my examples:

- [https://test.test.com/url1](https://test.test.com/url1) to pool1 then remove /url1
- [https://test.test.com/url2](https://test.test.com/url2) to pool2 then remove /url2
- [https://test.test.com/url3](https://test.test.com/url3) to pool3 then remove /url3
- [https://test.test.com/url4](https://test.test.com/url4) to pool4 then remove /url4
- [https://test.test.com/](https://test.test.com/) to pool5

This is what I ahve for the pool selection/redirection:

```tcl
when HTTP_REQUEST {
switch -glob -- [string tolower [HTTP::path]] {
    "/url1*" {
        pool /Common/Pool1
        return
    }
    "/url2*" {
        pool /Common/Pool2
        return
    }
    "/url3*" {           
        pool /Common/Pool3
        return
    }
    "/url4*" {
        pool /Common/Pool4
        return
    }
    "/*" {
        pool /Common/Pool5
        return
    }

}

```

Thanks all!!

---

<div class="post-metadata">

**Author:** ![stan\_piron](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@stan\_piron](https://community.f5.com/u/stan_piron)\
**Post date:** [July 1, 2015, 4:19pm UTC](https://community.f5.com/t/pool-selection-based-on-uri-and-url-modification/46377/2 "2015-07-01T16:19:58Z")

</div>

try this:

```tcl
when HTTP_REQUEST {
switch -glob -- [string tolower [HTTP::path]] {
    "/url1*" {
        pool /Common/Pool1
        HTTP::uri [string map { "/url1" ""} $uri]
        return
    }
    "/url2*" {
        pool /Common/Pool2
        HTTP::uri [string map { "/url2" ""} $uri]
        return
    }
    "/url3*" {           
        pool /Common/Pool3
        HTTP::uri [string map { "/url3" ""} $uri]
        return
    }
    "/url4*" {
        pool /Common/Pool4
        HTTP::uri [string map { "/url4" ""} $uri]
        return
    }
    default {
        pool /Common/Pool5
        return
    }

}

```

---

<div class="post-metadata">

**Author:** ![stan\_piron](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@stan\_piron](https://community.f5.com/u/stan_piron)\
**Post date:** [July 1, 2015, 4:23pm UTC](https://community.f5.com/t/pool-selection-based-on-uri-and-url-modification/46377/3 "2015-07-01T16:23:29Z")

</div>

same code without html conversion of quote:

```tcl
when HTTP_REQUEST {
switch -glob -- [string tolower [HTTP::path]] {
    "/url1*" {
        pool /Common/Pool1
        HTTP::uri [string map { "/url1" ""} $uri]
        return
    }
    "/url2*" {
        pool /Common/Pool2
        HTTP::uri [string map { "/url2" ""} $uri]
        return
    }
    "/url3*" {           
        pool /Common/Pool3
        HTTP::uri [string map { "/url3" ""} $uri]
        return
    }
    "/url4*" {
        pool /Common/Pool4
        HTTP::uri [string map { "/url4" ""} $uri]
        return
    }
    default {
        pool /Common/Pool5
        return
    }

}

```

---

<div class="post-metadata">

**Author:** ![Techitect](https://avatars.discourse-cdn.com/v4/letter/t/c6cbf5/32.png) [@Techitect](https://community.f5.com/u/Techitect)\
**Post date:** [July 21, 2015, 1:09pm UTC](https://community.f5.com/t/pool-selection-based-on-uri-and-url-modification/46377/4 "2015-07-21T13:09:44Z")

</div>

Hi Stanilas,

When I implemented your code additions, I received the following errors on traffic with the specific URI criteria:

Jul 20 15:37:26 F5EXLB01 info tmm2[16571]: Rule /Common/URI\_rule : HTTP path for 192.168.100.100 is /url4/XISOAPAdapter/MessageServlet

Jul 20 15:37:26 F5EXLB01 err tmm2[16571]: 01220001:3: TCL error: /Common/URI\_rule - can’t read “uri”: no such variable while executing “string map { “/url4” “”} $uri” (“/url4_" arm line 3) invoked from within "switch -glob -- [string tolower [HTTP::path]] { "/url4_” { pool /Common/Pool\_URL4\_443 HTTP::uri [string map { “/url4” “”} $uri…"

Thanks!

---

<div class="post-metadata">

**Author:** ![mimlo\_61970](https://avatars.discourse-cdn.com/v4/letter/m/bbe5ce/32.png) [@mimlo\_61970](https://community.f5.com/u/mimlo_61970)\
**Post date:** [July 21, 2015, 2:41pm UTC](https://community.f5.com/t/pool-selection-based-on-uri-and-url-modification/46377/5 "2015-07-21T14:41:51Z")

</div>

It looks like $uri is not defined anywhere. I think the intent is to have it set to HTTP::uri, so you can substitute [HTTP::uri] where $uri is.
