How to add an HSTS header to your website
Add a Strict-Transport-Security response header to your HTTPS pages, usually with one line in your server, CDN or host settings. Make sure HTTPS works everywhere on your site first, then start with a short lifetime and raise it once everything looks fine.
HSTS (HTTP Strict Transport Security) is a single line your server sends with each page. It tells browsers: "for the next while, only talk to this site over HTTPS." If it is missing, your site still works, but nothing forces visitors onto the secure version, and security scanners will flag it. Adding it is a small change, but a few checks beforehand will save you trouble.
What a missing HSTS header looks like
Most visitors notice nothing. You usually find out from a security scan, an audit report, or a header checker that lists Strict-Transport-Security as missing. A correct header looks like this:
Strict-Transport-Security: max-age=31536000; includeSubDomains
max-age is how long, in seconds, the browser should remember the rule. 31536000 seconds is one year. includeSubDomains applies the rule to every subdomain too.
Why it matters
Without HSTS, a visitor who types yourbusiness.com or clicks an old http:// link first makes an unencrypted request, and only then gets redirected to HTTPS. On public Wi-Fi or another untrusted network, an attacker can interfere with that first request and keep the visitor on an unencrypted or fake copy of your site. Once a browser has seen your HSTS header, it skips the insecure step and goes straight to HTTPS.
For a business site this is mostly about trust and due diligence. Security questionnaires, client IT teams and auditors often ask for it. HTTPS itself matters for search and visitor trust. HSTS is a hardening step on top, so do not expect it to change your rankings by itself.
How to check if your site has it
Three free ways:
- Run
curl -I https://yourdomain.comin a terminal and look for a line starting withstrict-transport-security. - In Chrome, Edge or Firefox, open developer tools (F12), go to the Network tab, reload, click the first request and look under Response Headers.
- Paste your address into a free online header checker such as securityheaders.com.
Check both the www and non-www versions, and check the HTTPS address. Browsers ignore the header on plain HTTP, so a missing header there is normal. SiteMonday's week 2 security scan also reports a missing HSTS header, once you have proved you own the site.
Before you add it
HSTS is a promise to browsers that HTTPS will keep working. If you break that promise, visitors who have already seen the header cannot simply click past a certificate warning. So check these first:
- Your HTTP address redirects to HTTPS. If it does not, see HTTP not redirecting to HTTPS.
- Pages do not load images, scripts or styles over
http://. See mixed content warnings. - Your certificate is valid and renews automatically.
- If you plan to use
includeSubDomains, every subdomain (shop, mail web pages, staging, old tools) must work over HTTPS too.
Then roll out in steps. Start with max-age=300 (five minutes), test, move to max-age=86400 (one day), and finally to max-age=31536000 (one year).
About preload: you may see preload added to the header and a site called hstspreload.org. That puts your domain on lists built into browsers, and it can take a long time to get removed again. Skip it unless you are sure every subdomain will support HTTPS for the long term.
How to add the header
The header must be sent by whatever serves your pages. Where that is depends on your setup. Menu names vary by version, so look for the wording below.
Nginx. In the server block that listens on port 443, add this line, then test and reload with nginx -t followed by nginx -s reload:
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
Apache. The mod_headers module must be enabled. Add this to the HTTPS virtual host, or to .htaccess, then reload Apache:
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"
Cloudflare. Look under SSL/TLS, then Edge Certificates, for an HSTS setting. It lets you pick max-age and subdomain options. Cloudflare then adds the header at its edge, so HTTPS must already work between visitors and your site.
WordPress. WordPress itself does not send server headers. Add the header in the web server config as above, or in the .htaccess file in your site folder if you are on Apache (back it up first and place the line outside the # BEGIN WordPress block). Many hosts also offer an HSTS or security headers option in their control panel, or their support can add it for you. There is a WordPress guide with more detail.
IIS. Newer versions of IIS Manager have an HSTS option for each site (look in the Actions pane). On older versions, add a custom header named Strict-Transport-Security in web.config under system.webServer, then httpProtocol, then customHeaders.
Netlify. Add a _headers file in your published folder, or a headers section in netlify.toml, with Strict-Transport-Security: max-age=31536000 for all paths.
Vercel. Add a headers entry in vercel.json for the source /(.*) with the key Strict-Transport-Security and your value.
If you are not sure which of these applies, ask your host or developer which server software and CDN sit in front of the site.
How to confirm the fix worked
- Run
curl -I https://yourdomain.comagain and confirm thestrict-transport-securityline appears with the value you set. - Check the
wwwand non-www versions, and a few inner pages. - If you use a CDN or caching plugin, clear its cache first, because an old cached response may not include the new header.
- Browse the site for a day or two and watch for certificate warnings or broken pages before raising
max-ageto the final value.
How to stop it coming back
The header usually disappears when the setup changes underneath it: a new host, a server rebuild, a CDN switch, or a config file that gets overwritten. Keep the line in a documented config (ideally one your developer keeps under version control), and add "check HSTS header" to your checklist for any migration or hosting change. Keep certificate renewal automatic, since an expired certificate is much more painful once HSTS is active. Finally, recheck the header with the free methods above after any change.
Step by step for your platform
- Missing HSTS header on Nginx
- Missing HSTS header on Apache
- Missing HSTS header on Cloudflare
- Missing HSTS header on WordPress
- Missing HSTS header on IIS
- Missing HSTS header on Netlify
- Missing HSTS header on Vercel
Questions
What is the best HSTS max-age value?
31536000 seconds (one year) is the usual final value. Start with a short value like 300 and increase it in steps as you confirm HTTPS works everywhere.
Will adding HSTS break my website?
Not if HTTPS already works on every page and subdomain you cover. If it does not, visitors who have seen the header may be blocked until you fix HTTPS, which is why you test with a short max-age first.
Should I use includeSubDomains and preload?
Use includeSubDomains only when every subdomain works over HTTPS. Add preload only when you are certain, because removal from browser lists can take a long time.
Why does my HSTS header not show when I check with HTTP?
Browsers and checkers only honor the header when it arrives over HTTPS, so it is normally not sent or ignored on plain HTTP. Always test the https:// address.
Can I add HSTS on shared hosting without server access?
Often yes, through `.htaccess` on Apache hosts, a host control panel option, or by turning it on in Cloudflare. If none of those work, ask your host's support.
How do I remove or undo HSTS?
Serve the header with `max-age=0` over HTTPS, and browsers will forget the rule the next time they visit. Browsers that do not return keep the old rule until its original max-age runs out.