关于 Set-Cookie 的 domain 的问题

一般让 cookie 在所有子域都有效的话会写成这样

Domain=.segmentfault.com

我想问第一个点是必需的吗,写成下面这样有没有问题

Domain=segmentfault.com
阅读 5.7k
2 个回答

不是必须的。前置 "." 是旧规范 RFC 2109 (已作废)的要求。

An explicitly specified domain must always start with a dot.

而当前规范 RFC 6265 说了 Set-Cookie 时,domain 属性的前置 "." 会被忽略

Note that a leading %x2E ("."), if present, is ignored even though that character is not permitted

因此第二种写法是没有问题的

*.segmentfault.com 和 segmentfault.com的区别