HSTS explained: how to enable it, and how to undo it when it locks you out
What the Strict-Transport-Security header does, how to roll it out safely, why browsers show an error with no bypass button, and how to remove HSTS or the preload list.
· 7 min read · By the Spot Downtime team
HSTS (HTTP Strict Transport Security) tells browsers to use HTTPS for your domain and never fall back to HTTP. It closes the gap that a redirect from http:// to https:// leaves open, and it is one of the cheapest security improvements you can make. It is also sticky: once a browser has seen the header, it enforces it for as long as you said, even if you later break your certificate. That is why HSTS appears in so many "I can't open my own site" questions.
What the header does
Without HSTS, a visitor who types example.com makes a plain HTTP request first, and your server redirects them to HTTPS. An attacker on the same network can intercept that first request and keep the visitor on HTTP. With HSTS, the browser remembers that your site is HTTPS-only and upgrades the request itself before it leaves the machine. In Chrome's network log this shows as an internal 307 redirect that your server never saw.
The header is sent over HTTPS responses only (browsers ignore it on HTTP):
Strict-Transport-Security: max-age=31536000; includeSubDomains; preloadmax-ageis how many seconds the browser should remember the rule. 31536000 is one year. The timer resets every time the browser sees the header again.includeSubDomainsapplies the rule to every subdomain too, including ones you forgot about.preloadsignals that you want the domain in the browsers' built-in preload list. It does nothing by itself, see below.
What breaks when HSTS is on
Normally a certificate error in Chrome has an "Advanced" link that lets you continue. For an HSTS domain the browser removes that option. An expired certificate, a name mismatch or an incomplete chain becomes a hard stop:
- Expired certificate: visitors can't click through.
- Name mismatch: same, no bypass.
- Incomplete chain: same.
- A subdomain with no HTTPS at all, when
includeSubDomainsis set: it becomes unreachable in browsers that remember the rule.
This is the intended design, since a click-through is exactly what an attacker relies on. But it raises the cost of a missed renewal from "warning page" to "site is down for everyone who has visited before".
Roll it out in stages
Never start with a year and includeSubDomains. Increase the lifetime as you gain confidence:
- Fix mixed content and HTTP-only pieces first. Every subdomain you will cover must serve valid HTTPS. See mixed content warnings.
- Start with a short max-age. Use
max-age=300(five minutes) on the main domain only, with noincludeSubDomains, and test. - Raise it step by step: a day, a week, a month, then a year (
31536000). - Add includeSubDomains once you have listed all subdomains, including internal tools, staging sites and mail webmail hosts.
- Automate certificate renewal and watch it. HSTS makes an expired certificate costly, so make sure renewals work (see Let's Encrypt renewal failed) and set expiry alerts with enough lead time.
Setting the header
# nginx: "always" so the header is also sent on error responses
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;# Apache (mod_headers)
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"// Express, with the helmet package
import helmet from "helmet";
app.use(helmet.hsts({ maxAge: 31536000, includeSubDomains: true }));Many hosts and CDNs have a switch for it instead, for example Cloudflare's HSTS setting under SSL/TLS, Edge Certificates. If both your origin and the CDN send the header, check you don't end up with two conflicting values.
Preloading
Even with HSTS, the very first visit to a site is unprotected, because the browser hasn't seen the header yet. The preload list closes that gap: browsers ship with a list of domains that are HTTPS-only from the start. To qualify, you submit the domain at hstspreload.org, and it must serve a valid certificate, redirect HTTP to HTTPS, and send a header with max-age of at least one year, includeSubDomains and preload.
Preloading is close to permanent
Undoing HSTS
On the server
The browser keeps enforcing the rule until the timer runs out, so you can't just delete the header. To end it early, keep serving a working HTTPS site and send a zero lifetime. Any browser that visits will drop the rule:
Strict-Transport-Security: max-age=0This only reaches users who can load the site over valid HTTPS again. If the certificate is broken, fix the certificate first.
In your own browser
For a developer machine that is locked out of a domain (typically localhost or a staging name that once had HSTS):
- Chrome and Edge: open
chrome://net-internals/#hsts(oredge://net-internals/#hsts), type the domain under "Delete domain security policies" and delete it. Preloaded domains can't be removed here. - Firefox: clear the site's data and history for that site (forget about this site), which removes its HSTS entry.
- Safari: removing the website data for the domain in Settings, Privacy is the usual way, and a restart may be required.
Check what you actually send
Confirm the header is present, correct and not duplicated on the final URL, after redirects:
curl -sI https://example.com | grep -i strict-transport-securityMake the certificate the thing you watch
Because HSTS turns a certificate problem into a full outage, certificate health is the part to monitor. An SSL monitor tracks the certificate's expiry on every check and warns you before it lapses, and a regular website monitor confirms the site loads over HTTPS from three regions before it alerts. Add both for any domain that sends HSTS, and include the subdomains that fall under includeSubDomains.
Get new guides by email
Practical posts on monitoring, outages, error fixes and on-call, when they're published. No spam.
Keep reading
- SSL · TroubleshootingCertificate pinning and rotation: how to renew without breaking your appsPinned certificates turn a routine renewal into an outage for mobile apps and API clients. How to pin the public key, plan backup pins and rotate safely.November 9, 2026 · 7 min read
- SSL · DNS · TroubleshootingCAA records: why your certificate won't issue (and how to fix it)A CAA record tells certificate authorities which of them may issue for your domain. Learn the syntax, how to debug CAA failures from Let's Encrypt and others, and how to fix them.November 3, 2026 · 6 min read