Certificates

Enable HSTS without breaking your site

In short. HSTS is an instruction your website gives to browsers: "only connect to me over a secure connection". Without it, a visitor's very first connection can be hijacked, for example on public Wi-Fi. It's one line to add to your site's configuration, by your IT provider or hosting provider. Adding it takes a few minutes, but it should be turned on in stages over several days so nothing gets blocked.

HSTS is an HTTP header, Strict-Transport-Security, that tells the browser to use only HTTPS for your site for a given duration (max-age, in seconds). To enable it safely: check that the whole site works over HTTPS, send the header with a short max-age, then raise it in steps up to one year. Only add includeSubDomains if all your subdomains are on HTTPS.

Last checked: November 18, 2026, in the MDN documentation and on hstspreload.org.

Why HSTS

Without HSTS, the first visit of a visitor who types your-domain.com often goes out as http://, before your redirect to HTTPS. On public Wi-Fi, that first request can be hijacked. With HSTS, a browser that already knows your site goes straight to HTTPS.

Before you start

  • The site already redirects http:// to https:// (see Redirect HTTP to HTTPS).
  • All pages work over HTTPS, with no mixed content.
  • You know the list of your subdomains, and which ones are on HTTPS.

Why be careful: once the header is received, the browser refuses HTTP for the whole max-age duration. If a subdomain only works over HTTP and you set includeSubDomains, it becomes unreachable for those visitors.

Step 1: send the header, over HTTPS only

MDN states it: browsers ignore the header if it arrives over HTTP. The port 80 redirect must not send it; only HTTPS responses carry it.

Nginx, in the port 443 server block:

add_header Strict-Transport-Security "max-age=300" always;

Apache, in the port 443 virtual host (headers module enabled):

Header always set Strict-Transport-Security "max-age=300"

Cloudflare: Edge Certificates page, HSTS setting, Enable HSTS, then read the warning and confirm with I understand. Cloudflare warns that removing HTTPS before disabling HSTS makes the site unreachable for the whole max-age duration.

Step 2: ramp up in steps

Start short, check that nothing breaks, then lengthen. Example progression:

StepValueHow long the browser remembers it
1max-age=3005 minutes
2max-age=864001 day
3max-age=6048001 week
4max-age=315360001 year

Stay a few days at each step. A one-year duration is the one MDN gives as an example, and the one the preload list requires.

Step 3: includeSubDomains, if everything is on HTTPS

With includeSubDomains, the rule applies to all subdomains, present and future:

Strict-Transport-Security: max-age=31536000; includeSubDomains

MDN still advises sending the header from every subdomain.

Step 4 (optional): the preload list

The preload list is built into browsers: your site is on HTTPS from the very first visit. Conditions from hstspreload.org:

  • a valid certificate;
  • a redirect from HTTP to HTTPS on the same host;
  • all subdomains on HTTPS;
  • on the main domain, a header with max-age of at least 31536000 (one year), includeSubDomains and preload.
Strict-Transport-Security: max-age=63072000; includeSubDomains; preload

A strong commitment: hstspreload.org warns that submission "cannot be easily undone", that removal takes months, and that the site must meet these conditions permanently. Only do it if you are sure you can keep HTTPS everywhere.

Step 5: check

curl -sI https://your-domain.com | grep -i strict-transport-security

Our free security headers check verifies the header and gives you the line to add.

Check your domain for free. AttackScout checks HSTS, its duration and the preload list registration, as well as the redirect to HTTPS, from the Internet. Check my domain

If something goes wrong

To disable HSTS, send max-age=0 over HTTPS. MDN states it: this only takes effect when the browser comes back over HTTPS and receives the header; you cannot disable HSTS over HTTP. Hence the value of ramping up slowly.

Frequently asked questions

Our audit flags "HSTS too short". What should I do?

Raise max-age in steps up to 31536000, once you are sure the whole site works over HTTPS.

Does HSTS replace the redirect to HTTPS?

No. The redirect is for visitors who have never seen the header; HSTS is for later visits. You need both.

Should I register for the preload list?

It is not mandatory. The HSTS header alone already protects returning visitors. Preloading adds the very first visit, but commits the domain and all its subdomains for a long time.

Sources

Accessed on November 18, 2026.