Yup, sounds like you are on the right track.
As for having it work for both 80 and 443, that is going to depend on what you are trying to accomplish. If you mean you want the rule to work on both a http and https vip, then you can simply modify the rule as such:
when HTTP_REQUEST {
set server [HTTP::cookie "server"]
set entry [findclass $server $::staging_nodes]
if { $entry ne "" } {
node [getfield $entry " " 2] [IP::local_addr]
} else {
log "Bad server cookie: $server"
reject
}
}
and remove the port from the data group.
The node command takes either format: "node a.b.c.d:p" or "node a.b.c.d p". The latter form allows you to do things like above.
Depending on if you have different cookie designators for the https servers vs. the http servers, you could also just add them to the data group. And finally, yes you could just create two separate data groups, one for http and one for https.
Another thing you may want to consider is how the rule handles the case when the "server" cookie is not present. Currently, the rule will still try to look in the data group. You may want to add a clause like "if { [HTTP::cookie exists "server"] } { " at the top and another else log & reject statement at the bottom.