HSTS
HSTS (HTTP Strict Transport Security) is a response header that tells the browser to always use HTTPS for that domain, even if the user types http:// or clicks an old link.
The basic header
Strict-Transport-Security: max-age=31536000; includeSubDomains
max-age— how long the browser remembers the rule, in seconds.includeSubDomains— applies to every subdomain.preload— submits the domain to the browser preload list; hard to undo.
How to roll it out safely
- Make sure the whole site and all subdomains use HTTPS.
- Start with a short
max-age, such as 300 seconds. - Test the HTTP → HTTPS redirect and the certificate.
- Raise
max-agegradually. - Add
includeSubDomainsonly after every subdomain is safe. - Consider
preloadas the final step.
What to watch for
- It is hard to undo. A browser that has received HSTS will refuse HTTP until max-age expires.
- Subdomains are included. One subdomain without HTTPS can become unreachable.
- It does not replace a valid certificate. HSTS only forces HTTPS; the certificate still has to be correct.
- The CDN must pass the header. Make sure the edge does not strip it.
- HSTS does not protect the first visit. The browser applies the rule only after receiving the header.
- Preload is not a small decision. It requires every subdomain and is difficult to reverse.
Use curl -I https://example.com and look for strict-transport-security. Check it on every subdomain too.
FAQ
Does HSTS apply immediately?
No. The browser applies the rule after receiving the header over a valid HTTPS connection. The first visit can still use HTTP.
Can HSTS make a site unreachable?
Yes, if a subdomain does not support HTTPS. That is why you start with a short max-age and test every subdomain.
Is HSTS the same as an HTTPS redirect?
No. A redirect sends HTTP requests to HTTPS. HSTS tells the browser not to use HTTP in the first place.
Disclaimer: Hosting Wiki articles are prepared for educational and reference purposes. Hosting technology keeps evolving, so some technical details may change over time.