# Irule not working as expected

**URL:** <https://community.f5.com/t/irule-not-working-as-expected/41862>\
**Category:** Technical Forums\
**Tags:** irules, ltm, application-delivery\
**Created:** [October 17, 2016, 12:59pm UTC](https://community.f5.com/t/irule-not-working-as-expected/41862 "2016-10-17T12:59:11Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![sandiksk\_35282](https://avatars.discourse-cdn.com/v4/letter/s/94ad74/32.png) [@sandiksk\_35282](https://community.f5.com/u/sandiksk_35282)\
**Post date:** [October 17, 2016, 12:59pm UTC](https://community.f5.com/t/irule-not-working-as-expected/41862/1 "2016-10-17T12:59:11Z")

</div>

I created an irule when CLIENT\_ACCEPTED { set default\_pool [LB::server pool] }

when HTTP\_REQUEST { switch -glob [string tolower [HTTP::uri]] { “/customerdetails_" - "/webofferlist_” - “/membershipedit \*” { pool poolB } default { pool $default\_pool } } }

Any traffic with http header with the above string it need to go to pool B , if not the default pool . But all the traffic is just going to the default pool , please help me to get this irule working as expectected.

We are doing ssl offload on f5 and again re-encrypting the data from f5 to the backend servers.

---

<div class="post-metadata">

**Author:** ![ekaleido](https://avatars.discourse-cdn.com/v4/letter/e/e495f1/32.png) [@ekaleido](https://community.f5.com/u/ekaleido)\
**Post date:** [October 17, 2016, 2:09pm UTC](https://community.f5.com/t/irule-not-working-as-expected/41862/2 "2016-10-17T14:09:18Z")

</div>

Are you sure the HTTP::uri is matching? Put in a log command to verify.

inside the HTTP\_REQUEST trigger, and above the “switch”

```markup
log local0. "The URI is [HTTP::uri]"

```

---

<div class="post-metadata">

**Author:** ![Jinshu](https://avatars.discourse-cdn.com/v4/letter/j/8e7dd6/32.png) [@Jinshu](https://community.f5.com/u/Jinshu)\
**Post date:** [October 17, 2016, 2:13pm UTC](https://community.f5.com/t/irule-not-working-as-expected/41862/3 "2016-10-17T14:13:24Z")

</div>

Please give the exact URI you are trying to redirect.

---

<div class="post-metadata">

**Author:** ![lmiestc\_26212](https://avatars.discourse-cdn.com/v4/letter/l/d26b3c/32.png) [@lmiestc\_26212](https://community.f5.com/u/lmiestc_26212)\
**Post date:** [October 17, 2016, 2:34pm UTC](https://community.f5.com/t/irule-not-working-as-expected/41862/4 "2016-10-17T14:34:32Z")

</div>

Read this one [DevCentral - An F5 Technical Community](https://devcentral.f5.com/articles/switch-gone-wild-using-wildcards-with-the-tcl-quotswitchquot-command) especially the An example of the “contains” functionality where it selects a pool depending on of the URI and then if no prior match go to the default pool.

So if looking at your irule

```tcl
when HTTP_REQUEST {
  switch -glob [string tolower [HTTP::uri]] {
    "/customerdetails" -
    "/webofferlist" - 
    "membershipedit/" {
      If URI contains any of the above pool poolB 
    }
    default {
      No prior match so take some default action
      pool name_of_your_default_pool
    }
  }
  Uncomment below if you want to log and see which URI goes to what pool for troubleshooting 
  log local0. "URI: [HTTP::uri] Pool: [LB::server pool]"
}

```

---

<div class="post-metadata">

**Author:** ![lmiestc\_26212](https://avatars.discourse-cdn.com/v4/letter/l/d26b3c/32.png) [@lmiestc\_26212](https://community.f5.com/u/lmiestc_26212)\
**Post date:** [October 17, 2016, 2:41pm UTC](https://community.f5.com/t/irule-not-working-as-expected/41862/5 "2016-10-17T14:41:09Z")

</div>

Don’t know how to get the edit working in this GUI but the poolB should look like this whith the when HTTP\_Reguest first

```markup
"*/customerdetails*" -
     "*/webofferlist*" -
     "*membershipedit/*"
    {
      If URI contains any of the above
     pool poolB
     }

```

- please see the [https://devcentral.f5.com/s/articles/switch-gone-wild-using-wildcards-with-the-tcl-quotswitchquot-command](https://devcentral.f5.com/s/articles/switch-gone-wild-using-wildcards-with-the-tcl-quotswitchquot-command) and you see the proper syntax

---

<div class="post-metadata">

**Author:** ![VernonWells](https://avatars.discourse-cdn.com/v4/letter/v/dec6dc/32.png) [@VernonWells](https://community.f5.com/u/VernonWells)\
**Post date:** [October 17, 2016, 9:02pm UTC](https://community.f5.com/t/irule-not-working-as-expected/41862/6 "2016-10-17T21:02:54Z")

</div>

A few other nuances. Firstly, you may wish to use **HTTP::path** , rather than **HTTP::uri**. The latter includes Request Parameters (i.e., the stuff starting with the ampersand (&) is a Request Target). If your glob match always ends with an asterisk (\*) or you really do want to consider the Request Parameters as part of your match, then **HTTP::uri** is fine (or, in the latter case, required), but otherwise, **HTTP::path** is more correct (and, as a bonus, potentially shorter for the string comparison operation).

Secondly, unless you have a case-insensitive filesystem or are mangling the Request Target path (e.g., via Apache mod-rewrite) in a way that treats paths in a case-insensitive matter, you do not need to use **string tolower** (and you’re spending execution cycles without value).

See this recipe for an explanation of these two points:

- [iRule Recipe 1: Single URL Explicit Redirect](https://community.f5.com/topic/290613)

Finally, you do not need (and should not include) the **default** on the **switch**. You have already assigned the default pool to the Virtual Server. If the iRule doesn’t change the pool selected, then that is the pool that will be used. Again, if you include this **default** branch, it is costing you execution cycles without value (and may be disruptive if you later change the code or the default pool attached to the Virtual Server).

---

<div class="post-metadata">

**Author:** ![sandiksk\_35282](https://avatars.discourse-cdn.com/v4/letter/s/94ad74/32.png) [@sandiksk\_35282](https://community.f5.com/u/sandiksk_35282)\
**Post date:** [October 19, 2016, 2:02pm UTC](https://community.f5.com/t/irule-not-working-as-expected/41862/7 "2016-10-19T14:02:55Z")

</div>

how would my irule be if need to remove this line HTTP\_REQUEST { switch -glob [string tolower [HTTP::uri]]

does it need to be HTTP\_REQUEST { switch -glob [string [HTTP::uri]]. I see the traffic hiiting the irule ,but when i see in show sys connection dont see anything for pool b member all the traffic is going to the default pool members.

---

<div class="post-metadata">

**Author:** ![sandiksk\_35282](https://avatars.discourse-cdn.com/v4/letter/s/94ad74/32.png) [@sandiksk\_35282](https://community.f5.com/u/sandiksk_35282)\
**Post date:** [October 19, 2016, 2:11pm UTC](https://community.f5.com/t/irule-not-working-as-expected/41862/8 "2016-10-19T14:11:23Z")

</div>

when I try using this HTTP\_REQUEST { switch -glob [string [HTTP::uri]], it is throwing an exception.

This is the url path I am seeing in the /var/log file [https://abc.com/customer/connectors/CustWeb.asmx/MembershipEdit](https://abc.com/customer/connectors/CustWeb.asmx/MembershipEdit)

---

<div class="post-metadata">

**Author:** ![VernonWells](https://avatars.discourse-cdn.com/v4/letter/v/dec6dc/32.png) [@VernonWells](https://community.f5.com/u/VernonWells)\
**Post date:** [October 19, 2016, 10:28pm UTC](https://community.f5.com/t/irule-not-working-as-expected/41862/9 "2016-10-19T22:28:05Z")

</div>

No need for any **string** command. If you don’t want to normalize the case, then:

```markup
when HTTP_REQUEST {
    switch -glob [HTTP::uri] {
        ... etc ... 
    }
}

```

However, again, you probably want to use **HTTP::path** , since that’s what you’re actually matching on. For the case your provide, it would be something like this:

```markup
when HTTP_REQUEST {
    switch -glob [HTTP::path] {
        "*/MembershipEdit" {
            pool poolB
        }
    }
}

```

For the example URL you provided, what you’re trying to match is essentially “if the Target-Request path ends\_with /MembershipEdit, then use poolB”. With glob matching:

```markup
switch [HTTP::path] {
        "/foo" {...} ; means match if path is exactly /foo
        "*/foo" {...} ; means match if path ends with /foo
        "/foo/*" {...} ; means match if path starts with /foo/
        "*/foo/*" {...} ; means match if path contains /foo/
    }

```

For what it’s worth, I suspect that what you _really_ mean is:

```markup
when HTTP_REQUEST {
    switch -glob [HTTP::path] {
        "*/CustomerDetails" -
        "*/WebofferList" -
        "*/MembershipEdit" {
            pool poolB
        }
    }
}

```

What I mean is, I suspect in all cases you are trying to match something at the end of the path, and since you are not normalizing the case (and generally, not normalizing the case of the path is the correct choice), then you must make sure the case matches.

---

<div class="post-metadata">

**Author:** ![sandiksk\_35282](https://avatars.discourse-cdn.com/v4/letter/s/94ad74/32.png) [@sandiksk\_35282](https://community.f5.com/u/sandiksk_35282)\
**Post date:** [October 20, 2016, 4:50pm UTC](https://community.f5.com/t/irule-not-working-as-expected/41862/10 "2016-10-20T16:50:58Z")

</div>

Thanks for your response . Tried the above syntax and it is working.
