Fix guides · Security
How to add the Strict-Transport-Security (HSTS) header
Make browsers always load your site over HTTPS, so visitors on public Wi-Fi can't be sent to an insecure copy. Steps for Shopify, WordPress, Webflow, Wix, Squarespace and Next.js.
- Time to fix
- 10 minutes
- Skill needed
- Copy and paste
- Who notices
- Visitors on public or shared Wi-Fi
Why it matters
Even with HTTPS set up, a visitor who types your address or follows an old http:// link makes one unencrypted request before being redirected. On public Wi-Fi, that first request can be intercepted.
The Strict-Transport-Security header tells browsers to skip that step and go straight to HTTPS for a set time, every visit after the first.
“User bookmarks or manually types http://example.com and is subject to a man-in-the-middle attacker”
Before you start
- Every page on your site must already work over HTTPS. Browsers will refuse plain HTTP for as long as the header says, and that can't be undone remotely.
- Start with a short time, like max-age=300 (5 minutes). Once everything works, raise it to a year: max-age=31536000.
- Only add includeSubDomains if every subdomain (shop., blog., mail. and so on) also works over HTTPS.
Fix it on your platform
Shopify Managed by the platform
- Shopify runs the servers for your store and doesn't let stores on its standard plans add or change response headers. There's nothing to edit in your theme.
- If this check matters to you (for example, for a security questionnaire), ask Shopify support whether HSTS is enabled for your domain. Stores on Shopify Plus or a headless setup (Hydrogen) can set their own headers.
WordPress
- Where you add the header depends on your hosting, not WordPress itself. First check your host's dashboard: many managed WordPress hosts have a security-headers or HSTS switch.
- On Apache hosting, add the line below to the .htaccess file in your site's root folder (back the file up first).
- On Nginx hosting, add the line below to your site's server block, then reload Nginx (or ask your host to).
- If your site runs through Cloudflare with the orange-cloud proxy on, you can switch HSTS on there instead: SSL/TLS → Edge Certificates → HTTP Strict Transport Security.
Header always set Strict-Transport-Security "max-age=31536000"add_header Strict-Transport-Security "max-age=31536000" always;Webflow Managed by the platform
- Webflow turns HSTS on automatically for every site that isn't on an Enterprise plan, and it can't be switched off. Custom security headers are an Enterprise feature.
- If we still flagged it, check Site settings → Publishing for HSTS options, and if there are none, ask Webflow support to confirm HSTS is active on your custom domain.
Wix Managed by the platform
- Wix hosts your site and doesn't let site owners add custom response headers, so this can't be changed from the Wix Editor.
- If you need it for compliance, contact Wix support and ask whether HSTS is enabled for your domain.
Squarespace
- Open your site's settings and find the SSL panel. Its location has moved between Squarespace versions: press / (slash) in the editor and search for "SSL" to jump there.
- Make sure Secure is selected, then turn on HSTS Secure.
- Squarespace notes changes can take a while to apply; re-run the audit after a few hours.
Next.js
- Add the header for every route in next.config.ts using headers().
- If you host on Vercel or Netlify, you can set it in vercel.json or netlify.toml instead; use one place, not both.
const nextConfig = {
async headers() {
return [
{
source: "/:path*",
headers: [{ key: "Strict-Transport-Security", value: "max-age=31536000" }],
},
];
},
};
export default nextConfig;Any other site
- Add the header where your site is served from: your web server, hosting control panel or CDN. Pick the example that matches your setup.
- Netlify: add it to a _headers file in your publish folder (or netlify.toml).
- Cloudflare (proxied, orange cloud): SSL/TLS → Edge Certificates → HTTP Strict Transport Security.
/*
Strict-Transport-Security: max-age=31536000Header always set Strict-Transport-Security "max-age=31536000"add_header Strict-Transport-Security "max-age=31536000" always;“We see a continuing increase in the number of pages using an HSTS header, with a rise of 6 percentage points compared to last edition, up to 36% of all pages visited on mobile.”
Check that it's fixed
- Re-run your StudioLNC audit: the "Missing Strict-Transport-Security header" issue should be gone.
- Or open your site, open your browser's developer tools → Network, click the first request and look for strict-transport-security under Response Headers.
Find every issue like this on your site
Free audit of performance, accessibility, SEO and security, with fixes for your platform.