# help making redirect irule

**URL:** <https://community.f5.com/t/help-making-redirect-irule/23894>\
**Category:** Technical Forums\
**Tags:** irules, dev, devops, application-delivery\
**Created:** [October 21, 2012, 10:40pm UTC](https://community.f5.com/t/help-making-redirect-irule/23894 "2012-10-21T22:40:46Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gill\_32697](https://avatars.discourse-cdn.com/v4/letter/g/958977/32.png) [@Gill\_32697](https://community.f5.com/u/Gill_32697)\
**Post date:** [October 21, 2012, 10:40pm UTC](https://community.f5.com/t/help-making-redirect-irule/23894/1 "2012-10-21T22:40:46Z")

</div>

Im new to irules, need some help writing a irule

vip: 10.1.255.32

node: 10.13.0.61

node: 10.0.1.213

Web programer wants any http request with

[http://test.com/Akcelerant/](http://test.com/Akcelerant/)…

[http://test.com/IDSAkcelerant/](http://test.com/IDSAkcelerant/)…

[http://test.com/LMAkcelerant/](http://test.com/LMAkcelerant/)…

[http://test.com/IDSAkcelerantMTG/](http://test.com/IDSAkcelerantMTG/)…

to hit pool member 10.13.0.61 otherwise goto 10.0.1.213.

they just need the f5 to pass the url with the path and have it hit the page otherwise go to

node 10.0.1.213.

Thanks

---

<div class="post-metadata">

**Author:** ![Mohamed\_Lrhazi\_1](https://avatars.discourse-cdn.com/v4/letter/m/d2c977/32.png) [@Mohamed\_Lrhazi\_1](https://community.f5.com/u/Mohamed_Lrhazi_1)\
**Post date:** [October 21, 2012, 11:22pm UTC](https://community.f5.com/t/help-making-redirect-irule/23894/2 "2012-10-21T23:22:51Z")

</div>

Might be better for you to use an HTTP class, instead of an iRule:

- Remove 10.13.0.61 from the pool.

- Add 10.13.0.61 to a new pool, call it my\_special\_pool

- Create and apply an HTTP class to the VIP, that :

-- matches any of the URIs you need matched.

-- Use my\_special\_pool

-- all other traffic will use the default pool.

---

<div class="post-metadata">

**Author:** ![Gill\_32697](https://avatars.discourse-cdn.com/v4/letter/g/958977/32.png) [@Gill\_32697](https://community.f5.com/u/Gill_32697)\
**Post date:** [October 22, 2012, 1:05am UTC](https://community.f5.com/t/help-making-redirect-irule/23894/3 "2012-10-22T01:05:09Z")

</div>

Ok I will try. Thank you Mohamed

Web developer said he will add more path to the header. He will adding

more /something. If I do use an irule and want to add both nodes to the pool and just pass the header intact that matches only the specified /path with a “else” statement that will point to the second node. Can you tell me the irule for that.

Its just incase I need it because I want do this first thing in the morning.

Thank you.

---

<div class="post-metadata">

**Author:** ![Gill\_32697](https://avatars.discourse-cdn.com/v4/letter/g/958977/32.png) [@Gill\_32697](https://community.f5.com/u/Gill_32697)\
**Post date:** [October 22, 2012, 1:10am UTC](https://community.f5.com/t/help-making-redirect-irule/23894/4 "2012-10-22T01:10:08Z")

</div>

Ok can you send me a sample of the http class rule, I’m not to good with scripting.

Web developer said he will add more path to the header.

He will adding more /something. If I do use an irule and want to add both nodes to the pool and just pass the header intact that matches only the specified /path with a “else” statement that will point to the second node. Can you tell me the irule for that.

Its just incase I need it because I want do this first thing in the morning.

Thank you.

---

<div class="post-metadata">

**Author:** ![nitass](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/nitass/32/2270_2.png) [@nitass](https://community.f5.com/u/nitass)\
**Post date:** [October 22, 2012, 1:25am UTC](https://community.f5.com/t/help-making-redirect-irule/23894/5 "2012-10-22T01:25:08Z")

</div>

you can add more uri to httpclass.

anyway, this is an example in case of irule.

```tcl
[root@ve10:Active] config b virtual bar list
virtual bar {
   snat automap
   destination 172.28.19.79:80
   ip protocol 6
   rules myrule
   profiles {
      http {}
      tcp {}
   }
}
[root@ve10:Active] config b class uri_class list
class uri_class {
   {
      "/akcelerant/"
      "/idsakcelerant/"
      "/idsakcelerantmtg/"
      "/lmakcelerant/"
   }
}
[root@ve10:Active] config b rule myrule list
rule myrule {
   when HTTP_REQUEST {
   set uri [HTTP::uri]
   if { [class match -- [string tolower $uri] starts_with uri_class] } {
      node 200.200.200.111
   } else {
      node 200.200.200.101
   }
}
when HTTP_RESPONSE {
   log local0. "[IP::client_addr]:[TCP::client_port] -> [clientside {IP::local_addr}]:[clientside {TCP::local_port}] -> [IP::remote_addr]:[TCP::remote_port] | $uri"
}
}

[root@ve10:Active] config cat /var/log/ltm
Oct 22 09:17:21 local/tmm info tmm[7926]: Rule myrule : 172.28.19.251:36438 -> 172.28.19.79:80 -> 200.200.200.111:80 | /Akcelerant/something
Oct 22 09:17:30 local/tmm info tmm[7926]: Rule myrule : 172.28.19.251:36439 -> 172.28.19.79:80 -> 200.200.200.111:80 | /IDSAkcelerant/something
Oct 22 09:17:34 local/tmm info tmm[7926]: Rule myrule : 172.28.19.251:36440 -> 172.28.19.79:80 -> 200.200.200.111:80 | /LMAkcelerant/something
Oct 22 09:17:39 local/tmm info tmm[7926]: Rule myrule : 172.28.19.251:36441 -> 172.28.19.79:80 -> 200.200.200.111:80 | /IDSAkcelerantMTG/something
Oct 22 09:17:42 local/tmm info tmm[7926]: Rule myrule : 172.28.19.251:36442 -> 172.28.19.79:80 -> 200.200.200.101:80 | /somethingelse/

```

---

<div class="post-metadata">

**Author:** ![Gill\_32697](https://avatars.discourse-cdn.com/v4/letter/g/958977/32.png) [@Gill\_32697](https://community.f5.com/u/Gill_32697)\
**Post date:** [October 22, 2012, 1:37am UTC](https://community.f5.com/t/help-making-redirect-irule/23894/6 "2012-10-22T01:37:09Z")

</div>

Ok, I will try. Thank You Very Much

---

<div class="post-metadata">

**Author:** ![Mohamed\_Lrhazi\_1](https://avatars.discourse-cdn.com/v4/letter/m/d2c977/32.png) [@Mohamed\_Lrhazi\_1](https://community.f5.com/u/Mohamed_Lrhazi_1)\
**Post date:** [October 22, 2012, 2:27am UTC](https://community.f5.com/t/help-making-redirect-irule/23894/7 "2012-10-22T02:27:49Z")

</div>

Ok can you send me a sample of the http class rule, I’m not to good with scripting.c

An http class is all GUI. No need to know scripting.

---

<div class="post-metadata">

**Author:** ![Gill\_32697](https://avatars.discourse-cdn.com/v4/letter/g/958977/32.png) [@Gill\_32697](https://community.f5.com/u/Gill_32697)\
**Post date:** [October 22, 2012, 6:03am UTC](https://community.f5.com/t/help-making-redirect-irule/23894/8 "2012-10-22T06:03:22Z")

</div>

Below is my irule, Im also showing the uri paths I need. I just don’t know how to add more to the irule to include

the other uri paths. As you can see I’ve added the Akcelerate uri path. But how do I add the rest?

I know is has to contain more IF staetments, but I don’t know how to write it. I new to the irules.

-[http://test.com/Akcelerant/](http://test.com/Akcelerant/)…

-[http://test.com/IDSAkcelerant/](http://test.com/IDSAkcelerant/)…

-[http://test.com/LMAkcelerant/](http://test.com/LMAkcelerant/)…

-[http://test.com/IDSAkcelerantMTG/](http://test.com/IDSAkcelerantMTG/)…

----- this is the irule im writing ---------------------------------------------------------

when HTTP\_REQUEST {

if { [HTTP::uri] contains “Akcelerant” } {

pool Server1-pool

} else {

pool Server2-pool

}

}

Thanks.

---

<div class="post-metadata">

**Author:** ![Mohamed\_Lrhazi\_1](https://avatars.discourse-cdn.com/v4/letter/m/d2c977/32.png) [@Mohamed\_Lrhazi\_1](https://community.f5.com/u/Mohamed_Lrhazi_1)\
**Post date:** [October 22, 2012, 6:17am UTC](https://community.f5.com/t/help-making-redirect-irule/23894/9 "2012-10-22T06:17:29Z")

</div>

nitass is showing you how to do this with a switch statement, instead of “if” and using a data class to hold your URIs, instead of hard coding them into the iRule, which a lot better.

go under: Local Traffic ›› iRules : Data Group List ›› New Data Group…

Create a String group called uri\_class, like in nitass example, put all your URIs there, as “String”, leave “Value” empty.

Create the iRule as in nitass example, just use “pool” instead of “node”

I still think you will better served by an HTTP class, instead of an iRule, given that you are not comfortable with scripting.

---

<div class="post-metadata">

**Author:** ![nitass](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/nitass/32/2270_2.png) [@nitass](https://community.f5.com/u/nitass)\
**Post date:** [October 22, 2012, 6:40am UTC](https://community.f5.com/t/help-making-redirect-irule/23894/10 "2012-10-22T06:40:11Z")

</div>

i agree with Mohamed. if you are not familiar with irule, you had better use httpclass.

sol13753: Using HTTP Classes to load balance HTTP requests to multiple pools

> **[404 Page not found | BIG-IP Documentation](https://techdocs.f5.com/kb/en-us/solutions/public/13000/700/sol13753.html)**
>
> Usage information and technical documentation for BIG-IP and other related F5 products

i used data group in previous example because i thought it would be easier to add or remove uri. anyway, if you do not want to use data group, you can use switch statement and put uri in the irule.

e.g.

```tcl
[root@ve10:Active] config b rule myrule list
rule myrule {
   when HTTP_REQUEST {
   switch -glob [HTTP::uri] {
      "/Akcelerant/*" -
      "/IDSAkcelerant/*" -
      "/LMAkcelerant/*" -
      "/IDSAkcelerantMTG/*" {
         pool Server1-pool
      }
      default {
         pool Server2-pool
      }
   }
}
}

```
