# Cookie persistence + iRule

**URL:** <https://community.f5.com/t/cookie-persistence-irule/19585>\
**Category:** Technical Forums\
**Created:** [May 19, 2015, 10:15am UTC](https://community.f5.com/t/cookie-persistence-irule/19585 "2015-05-19T10:15:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vova\_1985\_18320](https://avatars.discourse-cdn.com/v4/letter/v/e56c9b/32.png) [@Vova\_1985\_18320](https://community.f5.com/u/Vova_1985_18320)\
**Post date:** [May 19, 2015, 10:15am UTC](https://community.f5.com/t/cookie-persistence-irule/19585/1 "2015-05-19T10:15:42Z")

</div>

Hi,

I have VS configured with iRule and persistence profile:

iRule: when HTTP\_REQUEST { bla bla bla bla bla bla } else { pool DNN\_HTTP persist cookie insert lbhint 0

Persistence profile: Cookie Method: Insert Name: lbhint Always Send Cookie: Yes Expiration: Session Cookie

Now, my site configured to insert cookie named lbhint and the code checks if i dont have lbhint cookie it inserts it, then it checks each request if the cookie value equals to the servers that responded to my request, if it equals it does nothing, if its different it changes it to the server the responded.

Example: Request [http://www.mysite.com](http://www.mysite.com) (server-1 responded) --\> code checks lbhint exists (no) --\> insert lbhint=server-1 Request 2: (server-1 responded) --\> code checks lbhint exist (yes) --\> does it equal to server-1 (yes)? --\> do nothing Request 3: (server-2 responded) --\> code checks lbhint exist (yes) --\> does it equals to server-2 (no) --\> change value lbhint=server-2

Now, i want my LB to keep the session persistence based on this cookie but it doesn’t work, i tired to play with the profile methods, but no luck. When i check http headers i noticed that i see 2 cookies named lbhint, one with server value and the other is random chars and numbers (somthing like 34jbvh5vetv345vhj35). Another thing i noticed that it failed most of the time when my request from http switched to https (its 2 VS, one for http and another for https, and so i have to iRules, one for http pools and one for https pools).

1) As you noticed server name inserted in lbhint is server-1 however my NODE name in F5 is server\_1 (with underline) - Can it affect it? 2) Any ideas ti help me?

---

<div class="post-metadata">

**Author:** ![Vova\_1985\_18320](https://avatars.discourse-cdn.com/v4/letter/v/e56c9b/32.png) [@Vova\_1985\_18320](https://community.f5.com/u/Vova_1985_18320)\
**Post date:** [May 19, 2015, 12:00pm UTC](https://community.f5.com/t/cookie-persistence-irule/19585/2 "2015-05-19T12:00:48Z")

</div>

OK i actually want to make it easier: Ignore what my server does, lets focus only how to do it on F5 with standard cookie name. So i have 2 VS one for http and the other is https, they both configured to select pool by iRule, i need to configure cookie persistence across these 2 VSs. How can i do it right?

---

<div class="post-metadata">

**Author:** ![samstep](https://avatars.discourse-cdn.com/v4/letter/s/ea666f/32.png) [@samstep](https://community.f5.com/u/samstep)\
**Post date:** [May 19, 2015, 3:56pm UTC](https://community.f5.com/t/cookie-persistence-irule/19585/3 "2015-05-19T15:56:28Z")

</div>

Hi Vova,

Your message is quite confusing, it is difficult to understand what you are trying to achieve and what your requirements and problems are.

I can see at least one problem here - you are trying to persist using both Profiles and iRules (hence the problem of you getting two Set-Cookie headers in the response headers - one comes from Persistence profile and another one from your iRule).

If your requirement is just to persist across virtual servers you can use “Match Across Virtual Servers” checkbox in your persistence profile, BUT it has to be a Source-IP persistence, NOT Cookie persistence (no such option for Cookie Persistence)

If you need to use Cookie persistence, I recommend that you read these two DevCentral posts:

> **[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.

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

Hope this helps,

Sam

---

<div class="post-metadata">

**Author:** ![Vova\_1985\_18320](https://avatars.discourse-cdn.com/v4/letter/v/e56c9b/32.png) [@Vova\_1985\_18320](https://community.f5.com/u/Vova_1985_18320)\
**Post date:** [May 20, 2015, 6:47am UTC](https://community.f5.com/t/cookie-persistence-irule/19585/4 "2015-05-20T06:47:29Z")

</div>

My server provides to any request cookie named lbhint with value=servername, and i want to configure persistence based on this cookie on LB across 2 VS (same IP, one on port 80 and one on port 443 leading to the same servers). And its not working.

Config: http VS 1.1.1.1:80 --\> HTTP\_POOL:server1:80/server2:80 https VS 1.1.1.1:443 --\> HTTPS\_POOL:server1:443/server2:443

Example of what i need: First request: [http://www.mysite.com](http://www.mysite.com) it goes to http VS (lets assume LB redirected it to server1), now if i press “login button” it redirects me to: [https://www.mysite.com](https://www.mysite.com) so the request goes to https VS and at this stage i loose my persistent, instead of working with the sserver1 it goes to the server2.

And besides this i have irule (the last HTTPS\_POOL is the pool im talking about): And i have 2 irules like this, one for HTTP and the other for HTTPS.

```tcl
when HTTP_REQUEST {
   log local0.alert got request for [HTTP::uri];
   if {[string tolower [HTTP::uri]] starts_with /LpSys/} {
      Some_POOL
      persist none
      log local0.alert sending to LpSys pool
  } else {
      if {[string tolower [HTTP::uri]] starts_with /info/} {
          pool Some_POOL2
          persist cookie insert lbhint 0
          log local0.alert sending to info pool

      } else {
          if {[string tolower [HTTP::uri]] starts_with /mobile/} {
          pool SOME_POOL_3
          log local0.alert &quot;sending to mobile pool

         } else {
          pool HTTPS_POOL
          persist cookie insert lbhint 0
       }

    }
}
}

```
