Blog / How the internet works /
HSTS explained
You’ve installed an SSL certificate, your site shows the padlock, and you’ve redirected HTTP to HTTPS. Job done?
Almost. There’s one small gap, and HSTS closes it.
What HSTS is
HSTS stands for HTTP Strict Transport Security. In plain words: it’s a note your website gives to browsers saying, “From now on, only talk to me over HTTPS. Don’t even try the insecure version.”
It’s delivered as a response header, a small line of text sent along with your pages:
Strict-Transport-Security: max-age=31536000
That number is seconds, so 31536000 is one year. For the next year, a browser that has seen this header will refuse to load your site over plain HTTP and will switch to HTTPS by itself, before any request leaves the device.
The gap it fixes
Normally, if someone types yoursite.com without the https://, the browser first tries HTTP. Your server answers with a redirect to HTTPS. That very first request is unprotected.
On a trustworthy home network, no problem. On a public Wi-Fi network where someone is interfering with traffic, an attacker can intercept that first insecure request and keep the visitor on a fake or downgraded version. This is called an SSL-stripping attack.
HSTS removes the unprotected first step. After the browser has seen the header once, it never makes the HTTP request again.
An analogy: a redirect is a receptionist who says “this way to the secure entrance”. HSTS is the visitor memorising that the secure entrance is the only door.
Where it helps, and where it doesn’t
HSTS helps most when:
- Your visitors use public or shared Wi-Fi.
- You handle logins, forms or payments.
- You want to guard against accidental insecure links.
It doesn’t:
- Replace a valid SSL certificate. You still need one.
- Protect the very first visit ever, from a browser that has never seen your header. That’s what preloading is for.
- Make your site faster in any meaningful way, apart from skipping a redirect.
I explained the padlock side of this in HTTPS and the padlock: what it does and does not promise.
The three settings
max-age
How long the browser remembers. Start small (a few minutes or a day) while testing, then raise it to a year once everything works.
includeSubDomains
Applies the rule to every subdomain: blog.yoursite.com, shop.yoursite.com, even forgotten ones. Powerful and risky. If one old subdomain has no valid certificate, it breaks for everyone who has the header cached.
preload
An optional extra that asks browsers to ship your domain in a built-in list, so even first-time visitors get HTTPS. It’s a heavy commitment: removing a domain from the preload list takes a long time and depends on browser release cycles. I went into that in HSTS and HTTPS preload: one step beyond SSL.
How to switch it on
- Make sure HTTPS works everywhere first. Every page, every image, every subdomain you plan to include. Fix any mixed content (insecure images or scripts on secure pages) before you turn on strictness.
- Check your certificate renewal. If your certificate expires while HSTS is active, browsers won’t offer the “proceed anyway” option. Visitors get a hard block.
- Add the header with a short max-age. Options include your hosting control panel, a CDN setting (Cloudflare has an HSTS switch), a server config line, or a plugin.
- Test. Open your site in a private window and look at the response headers in your browser’s developer tools (Network tab).
- Raise max-age gradually. A day, then a week, then a month, then a year.
- Only add
includeSubDomainsorpreloadwhen you’re sure.
The mistakes that hurt
- Setting a year straight away, then discovering a subdomain without HTTPS.
- Letting the certificate lapse. With HSTS, an expired certificate is not a warning; it’s a wall.
- Forgetting about email or staging subdomains when using
includeSubDomains. - Turning it on while the site still has mixed content.
The lesson is the same as with most security settings: it’s easy to turn on and awkward to take back, so go slowly.
A quick way to check it’s working
Load your site in a private window and open the developer tools. In the Network tab, click the first request and read the response headers. You should see strict-transport-security with your max-age value. Then type your address with http:// at the start. After the first successful visit, the browser should jump straight to HTTPS without waiting for a redirect from your server; some tools show this as an “internal redirect”.
If the header is missing on some pages, something in front of your site (a CDN, a cache, a plugin) may be stripping or skipping it. Check that error pages and subdomains send it too. Consistency is the point.
Key takeaways
- HSTS tells browsers to use HTTPS only for your domain.
- It closes the gap on the first, unprotected HTTP request.
- Start with a short max-age and increase it.
- Be careful with includeSubDomains and preload.
- A valid, auto-renewing certificate is non-negotiable.
FAQ
Do I need HSTS on a small blog?
It’s a nice extra rather than a must-have. The basics (valid certificate, HTTP redirecting to HTTPS) matter far more.
Does HSTS affect SEO?
Not directly. Search engines care that your site is on HTTPS, which you already have.
How do I undo it?
Serve the header with max-age=0. Browsers that visit again will clear their memory, but those that don’t revisit keep the old rule until it expires.
Related reading
Before you add it, can you list every subdomain you own and say whether each has a working certificate? If not, that’s your first job.