Forum Discussion
Aaron_Magruder_
Nimbostratus
Feb 22, 2005Insert Cookie for a different domain
Is it possible to insert a cookie for domain xyz.domain.com when a customer visits abc.domain.com, then redirect them to xyz.domain.com?
When the customer gets redirected, I would like to have the BigIP look for the cookie that I inserted when they visited abc.domain.com. If the cookie exists, use pool xyz, if not redirect them to abc.domain.com to get a cookie.
Here is what I have come up with so far, but the cookie insertion isn't working. I am getting redirected back and forth between web sites.
Thanks for any assistance.
VS abc
rule abc_redirect
VS xyz
rule xyz1
rule abc_redirect {
when CLIENT_ACCEPTED {
set ckname xyz
set ckvalue [IP::client_addr]
set ckdomain xyz.domain.com
}
when HTTP_REQUEST {
HTTP::cookie insert name $ckname value $ckvalue path / domain $ckdomain
HTTP::redirect "https://xyz.domain.com"
}
rule xyz1
when CLIENT_ACCEPTED {
set ckname xyz
set ckvalue [IP::client_addr]
set ckdomain xyz.domain.com
}
when HTTP_REQUEST {
if {[HTTP::cookie exists $ckname]} {
HTTP::cookie remove $ckname
pool xyz
}
else {
HTTP::redirect "https://abc.domain.com"
}
}
- bl0ndie_127134Historic F5 AccountAre you seeing the Set-Cookie being sent back as a response on the wire? I suspect that your user agent might be rejecting the cookies because the host name of the Set-Cookie is different that the current host name. In another words, I don't think you are allowed to do a Set-Cookie abc.domain.com from 123.domain.com.
- Aaron_Magruder_
Nimbostratus
No I don't see the cookie being sent back. It doesn't appear that my syntax is correct or that the BigIP won't send a cookie for a different domain. - rapmaster_c_127Historic F5 AccountPerhaps you mean to latch the HTTP_RESPONSE event instead of HTTP_REQUEST?
- Aaron_Magruder_
Nimbostratus
I have tried that too. I don't see the cookie being injected during a trace. I tried inserting a cookie by the persist and HTTP::cookie insert methods. - drteeth_127330Historic F5 AccountThe HTTP::redirect short-circuits the response and prevents the cookie from being inserted. This affects the explicit cookie insert as well as cookie persistence. However, you can accomplish what you're trying to do with the HTTP::respond command if you add the Set-Cookie header manually.
- bl0ndie_127134Historic F5 AccountHere is an example ...
set cookie [format "%s=%s; path=/; domain=%s" $ckname $ckvalue $domain] HTTP::respond 301 "Set-Cookie" $cookie
- Aaron_Magruder_
Nimbostratus
Thanks. I figured out the location field, got the cookie inserted based on your syntax and the redirect is working. - Aaron_Magruder_
Nimbostratus
I had the ckname and ckdomain set incorrectly. After correcting this issue, the redirect works. If the cookie is not presented to aac1, you are redirected back to aac to get a cookie.
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