You could use the domain command to do this:
http://devcentral.f5.com/wiki/default.aspx/iRules/domain
[domain
www.sub.my.domain.com 2] -> domain.com
You might want to check that the host header isn't an empty or an IP address first. Here is an untested example:
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
}
}
Aaron