Security headers
The Strict-Transport-Security (HSTS) header tells browsers to only ever connect to your site over HTTPS for a set period, even if someone types http:// or follows an old link.
Not sure whether your site has this problem? Check it in seconds.
Without it, the very first request to your site can go over plain HTTP, where a network attacker can intercept or redirect it (a downgrade attack). HSTS closes that gap for returning visitors.
Look for Strict-Transport-Security in the response headers of your HTTPS site, or run our Security Headers checker. Note: browsers ignore the header on plain HTTP responses.
Header value
Strict-Transport-Security: max-age=31536000; includeSubDomainsNginx
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;Apache
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"Next.js (next.config.ts)
const nextConfig = {
async headers() {
return [
{
source: "/:path*",
headers: [{ key: "Strict-Transport-Security", value: "max-age=31536000; includeSubDomains" }],
},
];
},
};
export default nextConfig;No. Keep the redirect: HSTS only takes effect after a browser has seen the header once over HTTPS.
Guidance is general. Test header and DNS changes on a staging copy first, and check your hosting provider's documentation for platform-specific steps.