In short
HSTS (HTTP Strict Transport Security) is a response header, Strict-Transport-Security, that asks the browser never to contact the domain over HTTP again for a given period. This check consists of making sure the domain is suited to it, setting the header with a short duration, then extending it in stages up to one or two years, and afterwards considering registration in the browsers' preload list. Once it is done, a visitor who types example.com or follows an old HTTP link goes straight to HTTPS, with no unencrypted request.
Why it matters
The redirect from HTTP to HTTPS leaves a gap: the very first request goes out unencrypted. On a hostile network, an attacker can intercept it and keep the visitor on an HTTP version they control. HSTS closes this door: after a first visit over HTTPS, the browser itself converts every http:// address to https:// before sending anything, and forbids clicking through a certificate error.
For the very first visit, there is a preload list (HSTS preload) built into browsers: registered domains are treated as HTTPS from the outset.
The downside is rigidity. The browser remembers the instruction for the whole max-age duration. If a certificate expires, if a subdomain covered by includeSubDomains has no HTTPS, or if you leave the CDN that provided the certificate, the affected visitors can no longer reach the site until the duration ends, with no button to bypass the error. Hence the “if appropriate” in the title.
For search engines, HSTS is not a ranking signal and does not replace the 301 redirect: Google recommends keeping server-side redirects, which are what its crawlers follow. The benefit is visitor security and the removal of one redirect round trip for returning visitors.
What it improves
- Security No more interceptable unencrypted first request for visitors who have already been to the site, and for everyone if the domain is preloaded.
- Speed The browser skips the HTTP to HTTPS redirect. One round trip saved on visits coming from HTTP links.
- Certificates A visitor cannot accept a fake certificate presented by an intermediary.
- Audits HSTS appears in every security scanner and in B2B customer questionnaires.
- Rankings and AI citations No direct effect.
How to check
curl -sI https://www.example.com/ | grep -i "^strict-transport-security"
curl -sI https://example.com/ | grep -i "^strict-transport-security"
Compliant result, once in steady state:
strict-transport-security: max-age=31536000; includeSubDomains
The header must appear on the main domain (including the bare domain, since it is the one that carries includeSubDomains for all subdomains) and only over HTTPS: sent over HTTP, it is ignored.
Before enabling includeSubDomains, take inventory of every subdomain, including those that do not serve a website (webmail, extranet, network device, internal tool). Search for %.example.com on crt.sh and in your DNS zone, then test each one:
for h in www blog shop mail extranet; do
printf "%-10s " "$h"; curl -s -o /dev/null -m 10 -w "%{http_code}\n" "https://$h.example.com/" || echo "failed"
done
Each subdomain must respond over HTTPS with a valid certificate, or not respond at all.
On the browser side, Chrome lets you view and delete the instruction stored for a domain at chrome://net-internals/#hsts. For the preload list, hstspreload.org shows a domain's status and the errors that prevent its registration.
How to implement
Before you start
HSTS is appropriate if:
- the whole site and every public subdomain serve HTTPS with a valid certificate;
- the redirect from HTTP to HTTPS (opens in a new tab) is in place and stable;
- certificate renewal is automated and monitored (opens in a new tab);
- no return to HTTP is being considered.
It is not, or only without includeSubDomains, if:
- some subdomains still serve HTTP (intranet, devices, old application, subdomain managed by a service provider);
- the domain is shared with services you do not control;
- the certificate depends on a service you might leave or pause (CDN, hosting platform).
Domains ending in .dev, .app or .page are already on the preload list at the TLD level: HTTPS is mandatory there anyway.
Gradual ramp-up, recommended by hstspreload.org, waiting for each duration to end before moving on to the next:
| Stage | Value | Observation period |
|---|---|---|
| 1 | max-age=300; includeSubDomains |
5 minutes |
| 2 | max-age=604800; includeSubDomains |
1 week |
| 3 | max-age=2592000; includeSubDomains |
1 month |
| 4 | max-age=31536000; includeSubDomains |
Steady state (1 year) |
| 5 (optional) | max-age=63072000; includeSubDomains; preload |
Before registering for preload |
If includeSubDomains is ruled out, apply the same progression without this directive, on each hostname. During the first stages, an error only blocks visitors for a few minutes or a few days.
Warning: getting onto the preload list is quick, but getting off it is slow. hstspreload.org warns that removal takes months to reach users through browser updates. Only add
preloadwhen the domain and all its subdomains, present and future, can stay on HTTPS only.
Apache
Versions Apache 2.4 (expr= condition from Apache 2.4.10).
In the HTTPS virtual host only (<VirtualHost *:443>), with mod_headers enabled:
Header always set Strict-Transport-Security "max-age=300; includeSubDomains"
In an .htaccess file, which also applies to HTTP requests, make the header conditional:
<IfModule mod_headers.c>
Header always set Strict-Transport-Security "max-age=300; includeSubDomains" "expr=%{HTTPS} == 'on' || %{HTTP:X-Forwarded-Proto} == 'https'"
</IfModule>
Increase max-age at each stage. Reload with sudo apachectl configtest && sudo systemctl reload apache2.
Nginx
Versions Nginx 1.18 and later; add_header_inherit directive from Nginx 1.29.3.
In the server block listening on 443, never in the port 80 one:
add_header Strict-Transport-Security "max-age=300; includeSubDomains" always;
If a location block contains its own add_header directives, the inherited HSTS header disappears for those URLs: repeat it, or put all your headers in a file included everywhere. From Nginx 1.29.3 (1.30 stable branch), add_header_inherit merge; in the server block keeps the inherited header alongside those of the location. Reload with sudo nginx -t && sudo systemctl reload nginx.
LiteSpeed
Versions LiteSpeed Web Server 6; OpenLiteSpeed 1.7 and later.
The .htaccess block from the Apache section works. On OpenLiteSpeed, add the header in Header Operations of the virtual host's root context.
Caddy
Versions Caddy 2.
Caddy does not add HSTS by itself:
www.example.com {
header Strict-Transport-Security "max-age=300; includeSubDomains"
root * /var/www/example
file_server
}
IIS
Versions IIS 10 version 1709 and later (Windows Server 2019 and later); URL Rewrite rule for earlier versions.
From IIS 10 version 1709, HSTS is built in. In applicationHost.config, in the site's <site> element:
<hsts enabled="true" max-age="300" includeSubDomains="true" redirectHttpToHttps="true" />
It can also be set with the IISAdministration PowerShell cmdlets, as in Microsoft's documentation. On an older version, add the header with an outbound rule of the URL Rewrite module restricted to HTTPS responses.
Cloudflare
Versions Cloudflare dashboard, all plans, November 2026.
In SSL/TLS > Edge Certificates, “HTTP Strict Transport Security (HSTS)” section:
- “Enable HSTS”, read the warning, “I understand”, then “Next”.
- “Max Age Header”: the smallest value offered to start with (the choice ranges from one to twelve months).
- “Apply HSTS policy to subdomains”: only if every subdomain is on HTTPS.
- “Preload”: leave it disabled until you have decided to register; it requires at least twelve months.
- “Save”.
Cloudflare only sends the header on HTTPS requests. While HSTS is active, do not switch records to “DNS only”, do not pause Cloudflare and do not change nameservers without having a valid certificate elsewhere: the site would become unreachable for visitors who have stored the instruction. To follow the five-minute and one-week stages exactly, set the header with a response header transform rule instead, then switch to this setting.
AWS
Versions AWS console, Amazon CloudFront, November 2026.
On CloudFront, create a custom response headers policy (Policies > Response headers > Create response headers policy), security headers section, Strict-Transport-Security: duration in seconds, includeSubDomains and preload checkboxes, and the option to override the value sent by the origin. Attach it to the distribution's behaviors. Note: the SecurityHeadersPolicy managed policy already enables HSTS with max-age=31536000, without stages: do not attach it before you are ready.
Plesk
Versions Plesk Obsidian 18.0, SSL It! extension.
In Websites & Domains > your domain > SSL/TLS Certificates (SSL It!), the HSTS option sets the duration and the inclusion of subdomains. Plesk documents two limitations: a valid certificate is required, and the header is not sent when the preferred domain is www. Users also report the lack of a preload option. In these cases, add the header yourself in Apache & nginx Settings, in the additional nginx directives field, with the line from the Nginx section.
cPanel
Versions cPanel & WHM 124 and later.
No dedicated screen: add the conditional block from the Apache section to public_html/.htaccess, after checking in Security > SSL/TLS Status that every domain and subdomain has a valid certificate.
Shared hosting
Same method, with the conditional .htaccess block. Some hosts offer an HSTS checkbox in certificate management: check with curl the value actually sent, and do not stack the checkbox and .htaccess, which would produce two headers.
Vercel
Versions Vercel platform, all plans, November 2026.
By default, Vercel sends Strict-Transport-Security: max-age=63072000; on custom domains, without includeSubDomains. To extend it to subdomains or prepare for preload, define the header in vercel.json:
{
"headers": [
{
"source": "/(.*)",
"headers": [{ "key": "Strict-Transport-Security", "value": "max-age=63072000; includeSubDomains; preload" }]
}
]
}
Netlify
Versions Netlify platform, all plans, November 2026.
Add the header in the _headers file of the publish directory, at the stage you want:
/*
Strict-Transport-Security: max-age=31536000; includeSubDomains
Netlify states that preload registration requires the domain to be reachable on the www subdomain.
WordPress
Versions WordPress 6.4 and later.
Set the header at the server or CDN level (previous sections). Security plugins that offer HSTS often only cover pages generated by WordPress, not static files, and can conflict with a header already set by the host. Check with curl that only one header is sent.
Shopify
Versions Shopify, all plans; Webflow, non-Enterprise plans; November 2026.
Shopify manages HTTPS and its headers for the store; you cannot change HSTS. On Webflow, the HSTS header is enabled automatically on non-Enterprise plans, with options for subdomains and preload in Site settings > Publishing > Advanced publishing options.
Laravel
Versions Laravel 10 to 13.
Let the web server or the CDN set HSTS, so that it also covers static files. Failing that, add it in a middleware, on secure requests only:
if ($request->isSecure()) {
$response->headers->set('Strict-Transport-Security', 'max-age=31536000; includeSubDomains');
}
Behind a proxy, isSecure() only returns true if the trusted proxies are declared: $middleware->trustProxies(at: ...) in bootstrap/app.php from Laravel 11, the $proxies property of app/Http/Middleware/TrustProxies.php on Laravel 10.
Next.js
Versions Next.js 15 and 16, App Router and Pages Router.
Add the header in next.config.js if the platform or the proxy does not already do so:
module.exports = {
async headers() {
return [
{
source: '/(.*)',
headers: [{ key: 'Strict-Transport-Security', value: 'max-age=31536000; includeSubDomains' }],
},
];
},
};
Preload registration
Once the steady state has been running for several weeks without incident:
- Switch to
max-age=63072000; includeSubDomains; preloadon the bare domain (at least one year required, two years given as an example). - Check the requirements on hstspreload.org: valid certificate, redirect from HTTP to HTTPS on the same hostname, every subdomain on HTTPS, header on the base domain.
- Submit the domain. The registration reaches browsers with their updates.
Common mistakes
- Starting at one or two years: the slightest error blocks visitors for the same duration.
includeSubDomainswithout an inventory: a webmail, extranet or network device on HTTP becomes unreachable.- Adding
preload“for the grade”: the directive amounts to consent to registration, and removal takes months. - Header sent only on
www:includeSubDomainsonly takes effect on the name that carries it; set onwww, it protects neither the bare domain nor the other subdomains. - Believing HSTS replaces the redirect: crawlers, tools and new visitors still need the 301 redirect.
- Leaving the CDN or turning off HTTPS with HSTS active: the site becomes unreachable for returning visitors until expiry.
- Two HSTS headers (host and application) with different values: unpredictable behavior and refusal of preload registration.
Frequently asked questions
Does HSTS improve SEO?
No, HSTS is not a ranking signal and does not replace the 301 redirect from HTTP to HTTPS, which Google recommends keeping. Its benefit is visitor security: after a first visit over HTTPS, the browser no longer sends any unencrypted request and forbids clicking through a certificate error. It also removes one redirect round trip for returning visitors arriving through an HTTP link.
What max-age value should I choose for HSTS?
Start small: five minutes, then one week, then one month, waiting for each duration to end without incident, as hstspreload.org recommends. The steady state is one year (31536000 seconds) or more. Registration on the preload list requires at least one year, with includeSubDomains and preload. A long duration from the outset turns the slightest certificate error into a prolonged lockout.
How do I roll back after enabling HSTS?
Send the header with max-age=0 on every HTTPS page: each browser forgets the instruction on its next visit. Those that do not come back keep it until the old duration expires. For a domain registered on the preload list, remove the preload directive, request removal on hstspreload.org, then allow several months before browser updates apply it.
Should includeSubDomains be enabled?
Yes if every subdomain, present and future, serves HTTPS with a valid certificate, including webmail, extranets and internal tools reachable through a name on the domain. No as long as a single subdomain still runs on HTTP: it would become unreachable for any visitor who has been through the main site. Without this directive, set HSTS on each hostname separately.
Resources
- MDN: Strict-Transport-Securitydeveloper.mozilla.org
- hstspreload.org: preload list, requirements and removalhstspreload.org
- RFC 6797: HTTP Strict Transport Securitydatatracker.ietf.org
- Cloudflare: HTTP Strict Transport Securitydevelopers.cloudflare.com
- Microsoft: HSTS support in IIS 10 version 1709learn.microsoft.com
- Amazon CloudFront: Use managed response headers policiesdocs.aws.amazon.com
- Vercel: HSTS and encryption and Netlify: HTTPS and HSTS preloadvercel.com
- Plesk: SSL It! extensionplesk.com
Updated on
Topic checklist (PDF)