# How do I create Sequential or Linked iRules?

**URL:** <https://community.f5.com/t/how-do-i-create-sequential-or-linked-irules/9116>\
**Category:** Technical Forums\
**Tags:** irules, dev, devops, application-delivery\
**Created:** [July 19, 2012, 10:02pm UTC](https://community.f5.com/t/how-do-i-create-sequential-or-linked-irules/9116 "2012-07-19T22:02:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chase\_Hoffman\_2](https://avatars.discourse-cdn.com/v4/letter/c/e99b99/32.png) [@Chase\_Hoffman\_2](https://community.f5.com/u/Chase_Hoffman_2)\
**Post date:** [July 19, 2012, 10:02pm UTC](https://community.f5.com/t/how-do-i-create-sequential-or-linked-irules/9116/1 "2012-07-19T22:02:50Z")

</div>

So I’m a bit of an F5 novice, so please forgive me if this question is stupid.

I have an iRule currently which is programmatically updated by a web app as web applications are deployed. It works great. Basically it redirects [PRODSITE.COM/CLIENTSPECIFCURI](http://PRODSITE.COM/CLIENTSPECIFCURI) to a PRODSERVERPOOL based on /CLIENTSPECIFICURI.

I’d like to create an iRule ahead of it such that anything arriving to [TESTSITE.COM](http://TESTSITE.COM) goes to TESTSERVERPOOL. Because of the programatically generated nature of the PRODSITE iRule, I’d like to avoid putting code into it if possible.

Can anyone shed some light on this for me?

---

<div class="post-metadata">

**Author:** ![Joe\_Pruitt](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/joe_pruitt/32/8438_2.png) [@Joe\_Pruitt](https://community.f5.com/u/Joe_Pruitt)\
**Post date:** [July 19, 2012, 10:18pm UTC](https://community.f5.com/t/how-do-i-create-sequential-or-linked-irules/9116/2 "2012-07-19T22:18:22Z")

</div>

You can assign multiple iRules to a given virtual. Just use the “priority” command to tell the LTM what order to process them in. Details are in the “priority” API documentation in the iRules wiki at

> **[DevCentral - An F5 Technical Community](https://community.f5.com/)**
>
> DevCentral is an online technical community where engineers and practitioners collaborate, share knowledge, and solve problems related to F5 technologies and industry trends.

I believe I wrote an article on iRule events a while back too that might shed some light onto things.

[https://devcentral.f5.com/Tutorials…vents.aspx](https://devcentral.f5.com/Tutorials/TechTips/tabid/63/articleType/ArticleView/articleId/165/iRules-101--11--Events.aspx)

Hope that helps…

-Joe

---

<div class="post-metadata">

**Author:** ![Chase\_Hoffman\_2](https://avatars.discourse-cdn.com/v4/letter/c/e99b99/32.png) [@Chase\_Hoffman\_2](https://community.f5.com/u/Chase_Hoffman_2)\
**Post date:** [July 19, 2012, 10:37pm UTC](https://community.f5.com/t/how-do-i-create-sequential-or-linked-irules/9116/3 "2012-07-19T22:37:00Z")

</div>

Joe,

Thanks for the help.

Having read your tutorial, I think I may have phrased my question badly.

What I was hoping to do was basically:

If host == testsite, go to pool testsite

If host != testsite, go to iRule prodsite

Since that isn’t possible, how do I do a rule where it checks if the host = testsite, and, if not, does nothing? Presumably then the next rule in the priority order would take effect (in this case the programatically generated iRule looking at URIs).

Thank you so much for your help.

---

<div class="post-metadata">

**Author:** ![Joe\_Pruitt](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/joe_pruitt/32/8438_2.png) [@Joe\_Pruitt](https://community.f5.com/u/Joe_Pruitt)\
**Post date:** [July 19, 2012, 11:04pm UTC](https://community.f5.com/t/how-do-i-create-sequential-or-linked-irules/9116/4 "2012-07-19T23:04:23Z")

</div>

That get’s a little more difficult as there isn’t a direct way to call an iRule from another iRule. What you’ll need to do is to create a session variable to handle state and you. Here’s some pseudo code that may help

**priority 100**

when HTTP\_REQUEST {

set PROCESS\_IRULE\_PRODSITE 1;

if { [HTTP::host] eq “testsite” } {

Assign target pool (if this is the default pool, this can be omitted).

pool testsite

Do not process prodsite iRule

set PROCESS\_IRULE\_PRODSITE 0;

}

}

**priority 200**

when HTTP\_REQUEST {

if { $PROCESS\_IRULE\_PRODSITE == 1 } {

Do something

}

}

I think that’s what you are going after.

-Joe

---

<div class="post-metadata">

**Author:** ![GavinW\_29074](https://avatars.discourse-cdn.com/v4/letter/g/a9a28c/32.png) [@GavinW\_29074](https://community.f5.com/u/GavinW_29074)\
**Post date:** [July 20, 2012, 10:55am UTC](https://community.f5.com/t/how-do-i-create-sequential-or-linked-irules/9116/5 "2012-07-20T10:55:32Z")

</div>

Are there only the 2 rules assigned to the VIPs doing Pool assignment?

As if that’s the case, couldn’t you just use ‘Event disable’ in your test iRule if it’s a test connection…

```markup
when HTTP_REQUEST {
 if { [HTTP::host] eq "testsite" } {
     Assign target pool (if this is the default pool, this can be omitted).
    pool testsite
     Do not process prodsite iRule
    event disable
  }
}

```

Cheers

Gav

---

<div class="post-metadata">

**Author:** ![Chase\_Hoffman\_2](https://avatars.discourse-cdn.com/v4/letter/c/e99b99/32.png) [@Chase\_Hoffman\_2](https://community.f5.com/u/Chase_Hoffman_2)\
**Post date:** [July 20, 2012, 2:23pm UTC](https://community.f5.com/t/how-do-i-create-sequential-or-linked-irules/9116/6 "2012-07-20T14:23:40Z")

</div>

Joe,

Thanks, I’ll give that a shot!

Gavin,

Yes, there are the only two iRules. I’ll try that one as well.

Thank you both so much for your help.
