ゆるテックノート

Why “www” showed up in front

Back in the day, “www.example.com” was the default look. “www” was a simple subdomain saying “this is the web server.” Not mandatory, but there were practical reasons it spread.

How “www” became a thing

Role-based host names such as www for the Web, mail for email, and ftp for FTP became familiar conventions. Neither HTTP nor DNS requires the name www.

Early habits

  • Role-based names make the intended service easier to recognize.
  • DNS labels made roles obvious: www=web server, ftp=file transfer, mail=SMTP/IMAP.
  • Names and machines are not necessarily one-to-one. Multiple names can share a server, and one name can lead to several servers.

DNS reasons and perks

Adding “www” sometimes simplified DNS and hosting setups.

Apex vs. CNAME

  • A zone apex such as example.com needs SOA and NS records. An ordinary CNAME cannot coexist with those at the same name, so www can be used as the CNAME pointing to a CDN.
  • www could be CNAME to CDN, while the apex used A/AAAA for on-prem or another role.

Cookies and subdomains

  • A cookie set by www without a Domain attribute is host-only. Domain=example.com also covers sibling subdomains; adding www alone does not isolate cookies.
  • An origin is determined by scheme, host, and port, so www and the apex have distinct origins. Cookie scope follows different rules.

Use it—or not—today

Operators can choose either name. Visitors cannot assume that adding or removing www reaches the same site; it may lead elsewhere or fail.

Why skip it

  • Short, clean URLs (serve from the apex).
  • Provider features such as ALIAS or CNAME flattening may return A/AAAA results for an alias target. These differ from publishing an ordinary CNAME at the apex; support is provider-specific.

Why keep it

  • Flexibility: CNAME www to CDN while apex does something else.
  • Cookie/CORS scope separation by subdomain.
  • Preserve existing URLs and SEO/bookmarks.

Practical tips

Whatever you choose, make it canonical.

Recommendations

  • For the same site, choose a canonical name and permanently redirect the other. HTTPS needs a valid certificate for the redirecting name too. A DNS CNAME alone does not change the browser URL.
  • HSTS preload is optional. Its requirements include includeSubDomains, so first ensure HTTPS can be maintained across all subdomains.
  • Check cookie domain settings and CORS origins match your choice.

Specifications and related reading

RFC 2181: CNAME / RFC 6265: Cookie Domain / Cloudflare: CNAME flattening / HSTS preload requirements
DNS basics / CORS and preflight