HSTS
What is HSTS? Strict-Transport-Security explained
The gap a redirect leaves open
Most websites redirect http:// to https://, and they should. But the redirect itself happens over an unencrypted connection. When someone types your address without https://, or follows an old link, that first request can be seen and altered by anyone in a position to interfere, such as whoever controls a dishonest public Wi-Fi network. They could keep the visitor on an unencrypted copy of your site without the redirect ever reaching them. This is called an SSL stripping attack.
How HSTS closes it
When a browser receives this header over HTTPS, it remembers your domain:
Strict-Transport-Security: max-age=31536000For the next max-age seconds (a year, in this example), that browser:
- changes any
http://address for your site tohttps://before sending anything, so there's no unencrypted first request to interfere with; - refuses to let the visitor click through a certificate warning on your site, so a forged certificate can't simply be accepted.
Browsers ignore the header if it arrives over plain HTTP, since an attacker could have added it. Note the limit: the protection starts after a browser's first secure visit, unless your domain is on the preload list described below.
The three settings
max-ageis how long browsers remember the rule, in seconds. It's required. 15552000 is six months and 31536000 is a year. Settingmax-age=0tells browsers to forget the rule.includeSubDomainsapplies the rule to every subdomain as well. Check all of them first, including anything rarely visited such as a webmail, staging or old campaign address. If one can't do HTTPS, it becomes unreachable for anyone whose browser has the rule.preloadsignals that you want your domain included in the HSTS preload list, which is built into browsers, so that even a first visit is protected. Its requirements include a max-age of at least a year, withincludeSubDomainsandpreload, on your main domain. Removal can take a long time to reach everyone, so it isn't a step to take casually.
How to turn it on safely
The risk with HSTS is that it does what it says. While the rule is in place, a browser that remembers it won't fall back to HTTP, and visitors can't click past a certificate error. If your certificate lapses, your site is unavailable to them until it's fixed. Work up to it in stages:
- Confirm HTTPS works everywhere: every page and every version of your domain, with and without www. Make sure the certificate renews automatically and that you know who is responsible for it.
- Start small with
max-age=300(five minutes), then check the site still behaves. - Increase in steps: a day (86400), then a week (604800), then a month (2592000), leaving time between each.
- Settle on at least six months. Many sites use a year.
- Consider
includeSubDomainsand preloading last, and only after checking every subdomain.
Set it at server level, or in your CDN if you use one. On Apache and nginx, that looks like this:
# Apache
Header always set Strict-Transport-Security "max-age=31536000"
# nginx
add_header Strict-Transport-Security "max-age=31536000" always;What our checker reports
We read the header from your home page response, and only when that page was reached over HTTPS:
- Set: a
max-ageof 15552000 seconds (six months) or more. - Short duration, Disabled or Invalid: flagged for attention when the value is under six months, is
max-age=0, or can't be read. - Not set: flagged for attention, as a recommendation. It doesn't mean your site has been compromised.
We don't assess includeSubDomains or preload, and we don't look up the preload list. The check tests your HTTP-to-HTTPS redirect and certificate separately. HSTS is one of the five protections in our security headers guide.
Common questions
If I have HSTS, do I still need a redirect from HTTP to HTTPS?
How do I undo HSTS?
Is six months a rule or a recommendation?
Run the free check
Check your website now. It's free, needs no account and takes a few seconds. You can read exactly how the check works and what it can't see, or find out more about the Security Checker on hostdada.co.uk.
Check your website now
Free, passive and takes a few seconds. No account needed.
Guides for website owners
- PHP security warning (October 2026)What the critical PHP fixes mean for your website.Read guide
- Check your PHP versionIs your PHP version supported? Check it against official data.Read guide
- Find your PHP version in WordPressStep-by-step, with or without dashboard access.Read guide
- WordPress security checkerWhat we can (and can't) see about WordPress sites.Read guide
- How the check worksEvery check explained, plus its limitations.Read guide
- Security headers explainedWhat each header does and how we judge it.Read guide
- Content Security PolicyHow to read a policy and roll one out safely.Read guide
- SSL certificate checkValidity, expiry and what certificate errors mean.Read guide
- X-Powered-By and version leaksWhat your site gives away, and how to remove it.Read guide
- Website hacked? What to checkThe signs, the first hour and a proper clean-up.Read guide