Forum Discussion
rjordan
Nimbostratus
Jul 30, 2010Setting the domain of a cookie
Up until now, we were able to handle all of our persistence needs with the default cookie persistence. Now we have an application running on www.foo.com and sub.foo.com. We need to maintain persistence across the subdomains (which point to the same VS).
When I access www.foo.com, the domain of the cookie is set to "foo.com", which is not valid for sub.foo.com. Setting the cookie domain to "(dot).foo.com" should fix my persistence issues, but I'm not quite sure how to accomplish this.
Would I create an iRule using the necessary HTTP::cookie settings, then associate it with a new cookie persistence profile? Can someone point me in the right direction with a basic example? I checked the code share and didn't find much that would help. I feel that if I could replicate the default cookie persistence with an iRule, then I could easily tweak the domain setting.
Thanks.
- hoolio
Cirrostratus
Hi, - rjordan
Nimbostratus
That did the trick! - hoolio
Cirrostratus
You could use the domain command to do this:when HTTP_REQUEST { if { [string match {*[a-zA-Z]*} [HTTP::host]]}{ set domain [domain [HTTP::host] 2] } else { set domain "" } } when HTTP_RESPONSE { Check if the persistence cookie exists in the response if {[HTTP::cookie exists "BIGipServer[LB::server pool]"] and $domain ne ""} { set the domain attribute on the persistence cookie HTTP::cookie domain "BIGipServer[LB::server pool]" $domain } }
- rjordan
Nimbostratus
That's exactly what I was looking for! My last question: I currently have an iRule that directs the request to a particular node based on a value in the uri string. Is it recommended to integrate the cookie persistence into the existing iRule or should I apply multiple iRules to the VS? - hoolio
Cirrostratus
The two rules shouldn't conflict with each other and serve different purposes, so I'd leave them as separate iRules applied to the same VS.
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects