What is HSTS (HTTP Strict Transport Security)?
HSTS is the Strict-Transport-Security response header that tells a browser to use only HTTPS for a host: later http:// requests are upgraded automatically and users cannot click through certificate errors. Send it only over HTTPS, start with a short max-age, and treat preloading as hard to undo.
- Browsers store the policy per host for max-age seconds and upgrade http:// to https:// before connecting.
- With HSTS active, users cannot bypass certificate errors, so an expired certificate means a full outage.
- Preload needs max-age of at least 31536000, includeSubDomains and preload, and is hard to remove.
What do the HSTS directives do?
| Directive | Effect | Notes |
|---|---|---|
| max-age=SECONDS | How long the browser remembers HTTPS-only | Required. 31536000 is one year; max-age=0 clears the policy |
| includeSubDomains | Applies the policy to all subdomains | Every subdomain must work over HTTPS first |
| preload | Opts into browser preload lists | Needs max-age of at least 31536000 and includeSubDomains |
Directives and behavior per MDN and RFC 6797.
How do you roll out HSTS safely?
- 01
Get HTTPS working everywhere
Every host you will cover, including internal and www subdomains, must serve a valid certificate.
- 02
Redirect HTTP to HTTPS
MDN recommends a 301 with an https Location header, with no HSTS header on that redirect.
- 03
Start with a short max-age
Begin with minutes or days so a mistake expires quickly, then increase it. Each header received resets the expiry.
- 04
Add includeSubDomains when ready
Only after every subdomain, including forgotten ones, works over HTTPS.
- 05
Raise to one year, then consider preload
Submit to the preload list only if you can keep HTTPS on the entire site long term.
How do you send the header?
# nginx: send on HTTPS responses only
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
# Apache (mod_headers)
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"
# What a preload-ready header looks like (MDN example uses two years)
Strict-Transport-Security: max-age=63072000; includeSubDomains; preloadWhich numbers matter?
Certificate expiry becomes an outage
With HSTS, browsers remove the proceed-anyway option, so an expired certificate blocks every visitor until it is fixed. hstspreload.org also warns that preload inclusion cannot easily be undone and removal can take months to reach users.
What should you check before turning HSTS on?
- Every subdomain, including old and internal ones, serves a valid HTTPS certificate
- HTTP redirects to HTTPS with a 301 and no HSTS header on the redirect
- Certificate renewal is automated and monitored, since users cannot bypass an expired certificate
- The header is added to HTTPS responses only, and your server sends it on error pages too if you want that
- The max-age is short for the first rollout and increased in stages
- You have decided deliberately whether to preload
Common questions
What is HSTS?
HSTS (HTTP Strict Transport Security) is a response header, Strict-Transport-Security, that tells browsers to access a host only over HTTPS. After one secure visit the browser upgrades future http:// requests automatically and blocks certificate-error click-through.
What max-age should I use for HSTS?
Start low, such as a few minutes or days, while testing, then raise it. The preload list requires at least 31536000 seconds (one year). MDN's preload example uses 63072000 (two years). Each response with the header resets the timer.
Is HSTS preload reversible?
Only with difficulty. hstspreload.org warns that inclusion cannot easily be undone, and removal can take months to reach users through browser updates. Submit only if HTTPS will work on your entire site and all subdomains for the long term.
Why is HSTS ignored on my HTTP site?
Browsers ignore the header when it arrives over plain HTTP, so a network attacker cannot inject or alter it. Send it on HTTPS responses, and have the HTTP version redirect to HTTPS.
How do I remove HSTS?
Send max-age=0 over HTTPS. Browsers apply this only when received securely, so HSTS cannot be turned off over HTTP. If you are on the preload list, you must also request removal, which takes time.
Keep reading
Watch your domains automatically
Aepto monitors expiry, DNS, SSL and uptime for every domain you own and alerts you when something changes. Free for 3 domains.