Skip to main content

HSTS

Updated: October 29, 2026
By Willya Randika

HSTS is a header that tells the browser to always use HTTPS when accessing a domain. Once the header is received, the browser will not try HTTP again until the policy expires. This reduces the risk of downgrade attacks and cookies sent over an insecure connection.

Basic header

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

max-age is in seconds. One year is 31,536,000 seconds. includeSubDomains extends the rule to every subdomain. preload asks browsers to add the domain to their preload list, but it is not a switch you can undo quickly.

The header only applies after the browser receives a valid HTTPS response. If the site is still reachable over HTTP without a redirect, HSTS does not protect the first visit.

Safe rollout

Start with max-age=300 or one day, then increase gradually. Make sure every subdomain supports HTTPS before adding includeSubDomains. An old subdomain or internal service that still uses HTTP can become unreachable.

Test with curl -I https://example.com and look for the strict-transport-security header. In DevTools, open Network, select the document request, and check Response Headers. Repeat on several subdomains.

Do not enable preload until you are certain. Removal from the preload list takes time and a new submission. If a service still uses HTTP, preload can cut off user access.

What to watch for

HSTS does not replace a valid certificate. The certificate must match the domain and must not be expired. For certificates, see Let's Encrypt and Wildcard SSL.

HSTS also does not protect against every attack. It secures transport, not the application. For another security header, see CSP. For HTTP and HTTPS context, see HTTP vs HTTPS.

If you use a CDN, make sure the header is not stripped or overwritten. Some origin and CDN configurations produce duplicate headers. Check the final response the browser receives, not only the server config.

Preload requirements usually include a valid certificate, an HTTP to HTTPS redirect, and includeSubDomains. Once a domain is on the preload list, browsers will not open HTTP at all. Test every subdomain, including the rarely used ones, before submitting. If an old service still uses HTTP, fix it first or leave preload off.

If a third-party service runs on a subdomain, coordinate before using includeSubDomains. HSTS cannot exclude individual paths, so every path on the domain must support HTTPS. Test from a browser that has never opened the domain and record the max-age value in the runbook.

FAQ

Can HSTS be undone?

You can lower max-age and wait for the policy to expire. If the domain is preloaded, removal is slower and must be submitted to browsers.

Does HSTS apply to subdomains?

Only with includeSubDomains. Without it, the rule applies only to the domain that sent the header.

Does HSTS replace an HTTP to HTTPS redirect?

No. A redirect is still needed for the first visit. HSTS protects later visits after the browser has received the header.

Disclaimer: Hosting Wiki articles are prepared for educational and reference purposes. Hosting technology keeps evolving, so some technical details may change over time.