# Need a Simple iRule

**URL:** <https://community.f5.com/t/need-a-simple-irule/7098>\
**Category:** Technical Forums\
**Tags:** irules, dev, devops, application-delivery\
**Created:** [January 8, 2009, 3:26pm UTC](https://community.f5.com/t/need-a-simple-irule/7098 "2009-01-08T15:26:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ramesh\_110176](https://avatars.discourse-cdn.com/v4/letter/r/3bc359/32.png) [@ramesh\_110176](https://community.f5.com/u/ramesh_110176)\
**Post date:** [January 8, 2009, 3:26pm UTC](https://community.f5.com/t/need-a-simple-irule/7098/1 "2009-01-08T15:26:02Z")

</div>

HI

I am new to iRules and have a need to check the content of a cookied, if it matches then I need to send to a pool if not re-direct it to a sorry page. Below is what I have:

when HTTP\_REQUEST {

if { [HTTP::cookie contains “abcdefgh”] }

{

pool test

}

else { [HTTP::redirect http:\\sorry.x.y]}

}

I have also tried using HTTP\_RESPONSE, the F5 takes the rule but in the statistics it fails each time its used.

Thanks for all your help.

---

<div class="post-metadata">

**Author:** ![jay\_41157](https://avatars.discourse-cdn.com/v4/letter/j/fbc32d/32.png) [@jay\_41157](https://community.f5.com/u/jay_41157)\
**Post date:** [January 8, 2009, 5:49pm UTC](https://community.f5.com/t/need-a-simple-irule/7098/2 "2009-01-08T17:49:35Z")

</div>

add this line and watch the logs…

log local0. “check for [HTTP::cookie contains]”

---

<div class="post-metadata">

**Author:** ![ramesh\_110176](https://avatars.discourse-cdn.com/v4/letter/r/3bc359/32.png) [@ramesh\_110176](https://community.f5.com/u/ramesh_110176)\
**Post date:** [January 8, 2009, 6:47pm UTC](https://community.f5.com/t/need-a-simple-irule/7098/3 "2009-01-08T18:47:21Z")

</div>

Hi

To clarify:

when HTTP\_REQUEST {

if { [HTTP::cookie contains “abcdefgh”] log local0.}

{

pool test

}

else { [HTTP::redirect http:\\sorry.x.y]}

}

Is this correct?

---

<div class="post-metadata">

**Author:** ![James\_Quinby\_46](https://avatars.discourse-cdn.com/v4/letter/j/4af34b/32.png) [@James\_Quinby\_46](https://community.f5.com/u/James_Quinby_46)\
**Post date:** [January 8, 2009, 6:51pm UTC](https://community.f5.com/t/need-a-simple-irule/7098/4 "2009-01-08T18:51:15Z")

</div>

Ramesh -

You want to do:

```tcl
when HTTP_REQUEST { 
  
 log local0. "check for [HTTP::cookie contains]"  
  
 if { [HTTP::cookie contains "abcdefgh"] } 
 { 
 pool test 
 } 
 else { [HTTP::redirect http:\\sorry.x.y]} 
  
 }

```

Also, what is the name of the cookie that is being tested?

---

<div class="post-metadata">

**Author:** ![ramesh\_110176](https://avatars.discourse-cdn.com/v4/letter/r/3bc359/32.png) [@ramesh\_110176](https://community.f5.com/u/ramesh_110176)\
**Post date:** [January 9, 2009, 7:53am UTC](https://community.f5.com/t/need-a-simple-irule/7098/5 "2009-01-09T07:53:48Z")

</div>

I am not sure of the name but we can give it a value, I am in the process of finding this out. So once I put this line, how do I check whats going on? Is there a command line command I can type to see the data?

---

<div class="post-metadata">

**Author:** ![ramesh\_110176](https://avatars.discourse-cdn.com/v4/letter/r/3bc359/32.png) [@ramesh\_110176](https://community.f5.com/u/ramesh_110176)\
**Post date:** [January 9, 2009, 12:19pm UTC](https://community.f5.com/t/need-a-simple-irule/7098/6 "2009-01-09T12:19:23Z")

</div>

Thanks for all your help, after much work I have created what I needed:

when HTTP\_REQUEST {

log local0. “check for [HTTP::cookie value]”

if { [HTTP::cookie value log local0. “Found cookie”

pool test

} else {

log local0. “No cookie”

HTTP::redirect “[http://sorry.x.y](http://sorry.x.y)”

}

}
