The gap HSTS closes
Even if your site redirects HTTP to HTTPS, the very first request a visitor makes may go out over plain HTTP — when they type your domain without https:// or follow an old link. On an untrusted network, that first request can be intercepted and the visitor kept on a fake HTTP version of your site. This is a classic man-in-the-middle attack.
HTTP Strict Transport Security (HSTS) tells browsers: "Only ever connect to this site over HTTPS."
How it works
Your server sends a response header such as:
Strict-Transport-Security: max-age=31536000; includeSubDomains
After seeing it once over HTTPS, the browser automatically upgrades every future request to HTTPS for the max-age period, and refuses to let users click through certificate errors.
The directives
max-age— how long, in seconds, browsers remember the rule. One year (31536000) is the common recommendation. Short values like 300 give little protection.includeSubDomains— applies the rule to every subdomain. Only add it once every subdomain supports HTTPS.preload— signals that you want to be included in browsers' built-in HSTS list.
Preloading
Browsers ship with a list of domains that are HTTPS-only from the very first visit. You can submit your domain at hstspreload.org if your header has max-age of at least one year, includeSubDomains and preload.
Preloading is powerful but hard to undo: removal can take months to reach all users. Only preload when you are confident every subdomain, now and in future, will use HTTPS.
Rolling it out safely
- Make sure HTTPS works everywhere, with a valid certificate — see SSL certificate security.
- Start with a short
max-age(for example one day) withoutincludeSubDomains. - Increase to one year once nothing breaks.
- Add
includeSubDomainsafter checking every subdomain. - Consider
preloadlast.
Common mistakes
- sending HSTS over HTTP (browsers ignore it there)
- a tiny
max-agethat expires before users return includeSubDomainswith an old HTTP-only subdomain still in use
Check and fix
HSTS is one of several headers every site should send — see HTTP security headers explained and how to fix security headers. Yrzo AI checks your HSTS value and tells you exactly what to change — run a free scan.
Related reading: How to Check Your Website's SSL/TLS Configuration · Cookie Security Flags Explained: Secure, HttpOnly and SameSite · Website Security Checklist Before Launch