Enabling HSTS without locking yourself out of your own site
To add an HSTS header safely, send Strict-Transport-Security: max-age=86400 on every HTTPS response first, confirm the whole site still loads cleanly, then raise the max-age over a few weeks towards 31536000 (one year), and only after that consider includeSubDomains and preload.
HSTS (HTTP Strict Transport Security) tells browsers to reach your site over HTTPS only, for the length of the max-age. That is a genuine win against downgrade and cookie-hijacking attacks. The catch is that the instruction is sticky, which is exactly what bites people who switch it on too aggressively.
This guide on how to add an HSTS header walks through the safe ramp, the two flags that catch people out, and how our free external scan reports back on your HSTS setup so you can confirm the change took effect.
What the HSTS header actually does
Strict-Transport-Security is a response header your server sends on HTTPS pages. Once a browser has seen it, it remembers (for the length of max-age) that this host must only be loaded over HTTPS. Even if someone types http:// or clicks an old http link, the browser rewrites it to https before any request leaves the device.
That removes the brief insecure first hop a plain http-to-https redirect still allows. The trade-off is the stickiness: the browser obeys the rule until the max-age runs out, and you cannot reach into a visitor's browser to clear it early.
- max-age (in seconds): how long the browser enforces HTTPS-only. This is the dial you ramp up.
- includeSubDomains: applies the rule to every subdomain, not just the host that sent the header.
- preload: opts you into the HTTPS-only list that ships inside browsers, applied before a visitor ever loads your site.
The safe ramp: a short max-age first, then increase
The golden rule when working out how to add an HSTS header is to make your first max-age small. If something is misconfigured (a subdomain still on http, a service that cannot do TLS), a short value clears itself quickly instead of haunting visitors for a year.
A sensible progression looks like this. Move to the next step only once the current one has run cleanly for real visitors.
- Step 1: max-age=86400 (one day). Ship it, then browse the whole site, including any login and checkout, over HTTPS.
- Step 2: max-age=2592000 (about a month) once a day has passed with no mixed-content or certificate surprises.
- Step 3: max-age=31536000 (one year), the value browsers expect for preload eligibility, once you are confident.
- At every step, make sure http:// already redirects to https:// and that no insecure (http) assets load on secure pages.
includeSubDomains: check every subdomain first
includeSubDomains forces HTTPS-only on all subdomains of the host that sent the header, including ones you may have forgotten: a legacy blog, a staging box, a mail or status subdomain, an internal tool.
Add it only after you have confirmed that every subdomain serves valid HTTPS with a certificate that matches. If one subdomain is still http-only or has a broken certificate, this flag can make it unreachable in browsers until the max-age expires. Audit your DNS first, then add the flag, then re-test.
Free, instant, no account
See your site's security grade in seconds.
Free, instant, and no account needed to see your grade.
Scan my site freePlain-English A to E grade in about 10 seconds. No account needed to see it.
preload: powerful, and genuinely hard to undo
preload is the one to be cautious with. Adding the token and submitting your domain to the browser preload list means browsers ship already knowing your site is HTTPS-only, with no first request needed. It is the strongest form of HSTS.
It is also the hardest to reverse. Removal is a manual request that takes weeks or months to roll out through browser releases, and the rule stays enforced the whole time. Treat preload as close to permanent.
Only preload when all of the following are true and you intend to stay HTTPS-only for the long term.
- max-age is at least 31536000 (one year).
- includeSubDomains is present and every subdomain genuinely works over HTTPS.
- The preload token is present and http:// to https:// redirects are in place site-wide.
- You are certain no current or future subdomain will ever need plain http.
How EB Security checks your HSTS header
Our free scan reads your live response headers from the outside and reports on HSTS in plain English: whether the header is present, and whether it carries a real max-age, since a max-age of 0 (or a missing one) protects nobody. If HSTS is absent it is flagged as a hardening gap.
A missing HSTS header nudges your grade rather than sinking it, because a plain http-to-https redirect still covers most visitors. The same scan confirms HTTPS is working, the certificate is trusted and in date, and that there is no mixed content, which are the things HSTS depends on. Run the check, fix any HTTPS basics it surfaces, add the header using the ramp above, then re-scan to confirm the value reads back correctly.
Add HSTS in stages: a one-day max-age first, ramp towards a year once it is proven, and only add includeSubDomains and preload after you are certain every subdomain is HTTPS-only, because preload is very hard to undo.