HSTS (HTTP Strict Transport Security) is an HTTP response header that tells the browser to connect to your site only over HTTPS, never HTTP. Once the browser receives it, it blocks any insecure load attempts for the defined period — even if the user manually types http://.
In short: HSTS upgrades your SSL certificate from a suggestion into a hard browser-level rule.
Why Isn't Having SSL Installed Enough?
When you install an SSL certificate and set up an HTTP-to-HTTPS redirect, a short vulnerability window still exists. Before the redirect fires, the browser sends a plain-text request. An attacker positioned between the user and your server — a man-in-the-middle — can intercept that request and serve a fake version of your site.
This attack is called SSL stripping: the connection is "downgraded" to HTTP without the user noticing. HSTS closes that window.
How HSTS Works Step by Step
- A user visits your site for the first time over HTTPS.
- Your server responds with the
Strict-Transport-Securityheader. - The browser stores that policy in its internal cache along with the domain and validity period.
- On subsequent visits, the browser internally converts any HTTP request to HTTPS before sending it over the network.
- If the SSL certificate is invalid or expired, the browser blocks access entirely — there is no "proceed anyway" option.
The header looks like this in a server response:
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
What Do the Parameters Mean?
| Parameter | Meaning |
|---|---|
max-age |
Seconds the browser enforces the policy. 31,536,000 = 1 year. |
includeSubDomains |
Extends the policy to all subdomains (e.g., blog.yourdomain.com). |
preload |
Signals that the domain wants to be included in browsers' HSTS preload list. |
The HSTS Preload List: Protection From the Very First Byte
The HSTS header protects users starting from the second visit. But the first visit can still be vulnerable. To eliminate that risk entirely, there is the HSTS preload list, maintained by Google and adopted by Chrome, Firefox, Edge, Safari, and Opera.
Domains on that list have HTTPS enforcement baked directly into the browser binary: no HTTP request is ever made, not even on the very first visit.
To request inclusion:
- Your domain must serve valid HTTPS.
- You need the header with a
max-ageof at least one year,includeSubDomains, and thepreloadflag. - Submit at hstspreload.org.
Warning: preload list inclusion is hard to reverse. Make sure every subdomain serves HTTPS before submitting.
How to Enable HSTS in Apache and Nginx
Apache (.htaccess or VirtualHost)
<IfModule mod_headers.c>
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
</IfModule>
Requires mod_headers to be active. In cPanel environments, it usually is.
Nginx
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
Place this line inside the server block of your SSL configuration.
If you manage your hosting through cPanel, you can also set security headers via the Security section or the .htaccess editor. For a complete, error-free setup, working with a specialized hosting team saves time and prevents misconfigurations.
Common Mistakes When Implementing HSTS
- Enabling it before HTTPS is on all subdomains. If
includeSubDomainsis set and a subdomain lacks SSL, users will be completely locked out. - Using a very long
max-agefrom the start. Begin with 300 seconds (5 minutes) to test, then raise to 31,536,000 once everything is confirmed working. - Thinking HSTS replaces the HTTP→HTTPS redirect. The redirect is still needed to serve the header on the first visit.
- Requesting preload before all subdomains are ready. Audit each subdomain before setting the
preloadflag.
Explore more complementary security headers in our SSL and HTTPS security resource center.
Key Takeaways
- HSTS is the HTTP header that forces browsers to use HTTPS always, closing the vulnerability window of the first HTTP hop.
- It protects against SSL stripping and protocol downgrade attacks.
- The
includeSubDomainsandpreloadparameters broaden and strengthen coverage. - The HSTS preload list eliminates the risk even on the very first visit.
- Start with a short
max-age, verify all subdomains, then increase the value.
Ready to lock down your site with HSTS and the rest of the security headers? Reach out to elenlace.com and we'll get it configured correctly from day one.
FAQ
Is HSTS the same as SSL?
No. SSL (or TLS) is the cryptographic protocol that encrypts the connection. HSTS is a browser policy that guarantees that encrypted connection is the only one allowed. Both work together: without SSL, HSTS is meaningless; without HSTS, SSL can be bypassed.
Does HSTS affect SEO?
Positively. Search engines favor HTTPS sites, and HSTS ensures no accidental HTTP version ever gets indexed. It also eliminates unnecessary redirects, which marginally improves page load speed.
How do I turn off HSTS if I make a mistake?
Serve the header with max-age=0 to clear it from the browser cache. However, if you are already on the preload list, removal can take months because it requires a browser binary update.
Does HSTS work in all modern browsers?
Yes. Chrome, Firefox, Edge, Safari, and Opera have supported HSTS for over a decade. Internet Explorer 11 also has partial support. For users with very outdated browsers, the HTTP→HTTPS redirect remains the fallback mechanism.
Useful resources
Other providers and guides worth comparing: