Reference guide · dns-ssl · Published 2026-08-16 · 4 min read

HSTS header and secure transport

HSTS header guide: what Strict-Transport-Security does, the max-age and includeSubDomains flags, preload, and safe rollout steps.

The problem HSTS solves

An HTTP to HTTPS redirect is a recommendation, not a guarantee. The first request of a session can still go out in clear text (port 80) before the redirect kicks in, and an attacker on the path can intercept that first hop, block the redirect, and serve a fake page. HSTS removes that window: the server tells the browser to remember, for a given period, that this domain must only ever be reached over HTTPS, so even a future plain-HTTP attempt is upgraded internally before anything leaves the machine.

Strict-Transport-Security: max-age=31536000; includeSubDomains is the header a server sends on an HTTPS response.

FlagMeaningRisk if wrong
max-ageSeconds the browser remembers the policyToo long + a bad config = a lockover lasting days
includeSubDomainsApply to every subdomainA subdomain you plan to serve over HTTP gets hard-redirected
preloadAsk Chrome's baked-in preload list to enforce HSTS on first ever visitHard to undo once accepted; submit only when fully green over a long rollout

The two-stage adoption

HSTS is safe when the zone is prepared, and fatal when it is not:

  1. Run HTTPS fully first. Every page, every request on the secure hostname, and all subdomains in includeSubDomains must serve HTTPS without mixed content. Check the existing HTTPS implementation against the mixed content article.
  2. Send a short max-age first (say 300). Confirm the site still works over HTTPS, that no subdomain unexpectedly 301s to HTTPS that is not ready, and that the certificate chain covers every hostname. Then raise to 31536000.
  3. For preload: after the period at long max-age, submit the domain to the HSTS preload list checklist once it shows fully green, because the preload entry survives even after the header is removed.

The failure to roll out in stages converts a configuration error at step two into a lockout that lasts the entire max-age.

How a site owner forces it

At the edge, the easier and common path is to let the CDN or hosting layer add the header. On Cloudflare, "Always Use HTTPS" plus the "HSTS" option under TLS sets max-age and includeSubDomains proxied for the whole zone. On nginx, the header is added at the server block:

add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;

Apache:

Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"

The always / always set matters: without it, some servers omit the header on 4xx/5xx responses, and a cached 404 would not renew the policy. Test with:

curl -sI https://example.com | grep -i strict

The hazards in practice

When to avoid HSTS

The HTTP scheme choice and SEO impact articles address whether 301 or HSTS matters in a given deployment. The certificate errors article is the list of what an unsolved HSTS lockout looks like from the browser side.

Need a website built, fixed, optimised, migrated or replaced?

This technical resource is written by CSMBAC, a small design and development studio. If you would rather hand the problem to a professional, the website service page explains how we build enquiry-ready websites.

Explore website services