How to set up HSTS
November 18, 2026
Send one response header from your HTTPS origin, Strict-Transport-Security: max-age=300; includeSubDomains, confirm that every subdomain still works, then raise the age in stages to a year or more. Browsers that have seen the header refuse to load the site over plain HTTP for that long, with no way for the user to click through. The staging is the whole discipline, because a long max-age on a site with one HTTP-only subdomain locks that subdomain out of every browser that visited.
What the header does
"The time, in seconds, that the browser should remember that a host is only to be accessed using HTTPS" is the max-age directive (MDN, Strict-Transport-Security). While that time runs, the browser rewrites every HTTP request to the host before sending it: "The UA MUST replace the URI scheme with 'https'" (RFC 6797, section 8.3). A certificate error on such a host is final: "the browser does not offer the user a way to proceed or 'click through' the error message, which would compromise the intention of strict security" (MDN), or in the RFC's words, "the user should not be presented with a dialog giving her the option to proceed."
The header is only honoured over HTTPS. "An HSTS Host MUST NOT include the STS header field in HTTP responses conveyed over non-secure transport" (RFC 6797, section 7.2), and "Browsers ignore the header if sent over HTTP" (MDN). The first visit over plain HTTP therefore depends on your redirect to HTTPS; every visit after it is covered by the remembered policy.
The rollout
hstspreload.org publishes the staged values, and the instruction between them: "5 minutes: max-age=300; includeSubDomains", then "1 week: max-age=604800; includeSubDomains", then "1 month: max-age=2592000; includeSubDomains", and "Fix any problems that come up and then wait the full max-age of the stage before you move on" (hstspreload.org). The waiting is the point: a browser that cached the one-month value keeps it for a month, so a mistake found on day two of that stage affects visitors for the rest of it.
Serve HTTPS on the host and on every subdomain, and redirect HTTP to HTTPS "on the same host, if you are listening on port 80" (hstspreload.org).
Add the header to the HTTPS responses only, at
max-age=300; includeSubDomains.Visit the site and each subdomain over HTTPS, then check that
http://addresses now redirect in a browser that has seen the header.Raise to a week, wait the week, raise to a month, wait the month.
Settle at a year or two. The RFC's example is
max-age=31536000and the preload site's ismax-age=63072000.
If something breaks, max-age=0 is the undo: "A max-age value of zero (i.e., 'max-age=0') signals the UA to cease regarding the host as a Known HSTS Host" (RFC 6797, section 6.1.1). It only reaches browsers that visit again, which is why the stages start at five minutes.
includeSubDomains
The directive "signals the UA that the HSTS Policy applies to this HSTS Host as well as any subdomains of the host's domain name" (RFC 6797, section 6.1.2). That includes subdomains nobody thinks of as websites. The RFC's first example of what goes wrong is a host that "offers unsecured HTTP-based services on alternate ports or at various subdomains of its HSTS Host domain name" (section 11.4), and the preload site reports the result: "We get regular emails from site operators who tried out HSTS this way, only to find themselves on the preload list without realizing that some subdomains cannot support HTTPS."
Before the directive goes on, list every hostname under the domain, internal ones included, and confirm each answers over HTTPS. The apex and www have their own trap: a header "sent only by example.com while the application lives at www.example.com" does nothing for www, since "the UAs will not receive or enforce the HSTS Policy" (RFC 6797, section 11.4.2). Send the header from every hostname that serves pages.
Preload
Preloading puts the domain into a list compiled into browsers, so even the first visit is forced to HTTPS: "If the browser loads an insecure http URL prior to knowing that the host is an HSTS host, the initial request is vulnerable to network attacks. Preloading mitigates this problem" (MDN). The requirements are "The max-age must be at least 31536000 seconds (1 year). The includeSubDomains directive must be specified. The preload directive must be specified", plus the redirect and HTTPS on every subdomain (hstspreload.org).
The list's own site now advises against it: "While HSTS is recommended, HSTS preloading is not recommended", because "inclusion in the preload list cannot easily be undone. Domains can be removed, but it takes months for a change to reach users with a Chrome update" (hstspreload.org). Leave the preload token off the header unless you have decided to submit, since the token is what the list's crawler looks for.
Testing
Read the header back from the HTTPS origin and from each subdomain with a tool that follows no redirects, and confirm it is absent from the HTTP responses. In Chrome, chrome://net-internals/#hsts shows whether the browser has recorded the host and with what expiry; the form at hstspreload.org reports what a preload submission would see. How to secure a login page is where the header earns its keep, since a login form over HTTP is the attack the header exists to prevent.
Sources
hstspreload.org, for the staged rollout, the preload requirements and its current advice
RFC 6797, HTTP Strict Transport Security, sections 6, 7, 8, 11 and 12