HSTS: make browsers always use HTTPS

hsts, https, security headers, preload, htaccess · 0 found this helpful

HSTS (HTTP Strict Transport Security) is a header that tells a visitor's browser to use only HTTPS for your site, for a set time. It closes the small gap where a first visit over http:// could be tampered with before the redirect.

Before you start

Turn HSTS on only when all of these are true.

Step 1: Start with a short test

Add the header with a five-minute lifetime. If anything breaks, it fixes itself quickly.

  1. Open Account → Hosting → your site → Files → File manager. Go to your site's folder, usually public_html.
  2. Edit .htaccess. Make a copy first. See .htaccess basics with examples.
  3. Add these lines.
<IfModule mod_headers.c>
  Header always set Strict-Transport-Security "max-age=300"
</IfModule>
  1. Save. Load your site over HTTPS and check the header with your browser's developer tools. Open the Network tab, click the first request, and look in Response Headers.
strict-transport-security: max-age=300

Step 2: Raise the lifetime in stages

max-age is in seconds. Move up one step at a time and wait a few days between steps.

Stage max-age Meaning
Test 300 5 minutes
Week 604800 7 days
Month 2592000 30 days
Full 31536000 1 year, the normal target

Final form.

<IfModule mod_headers.c>
  Header always set Strict-Transport-Security "max-age=31536000"
</IfModule>

Subdomains

Add includeSubDomains only if every subdomain you own, including ones you forgot, works over HTTPS.

Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"

A subdomain such as mail.example.ca or old.example.ca without a valid certificate becomes unreachable in browsers.

Preload: read this first

preload asks browser makers to ship your domain in a built-in list, so even the very first visit is forced to HTTPS.

Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"

Important: Preload is hard to undo. Removal from the list can take months, and until then your domain and every subdomain must work over HTTPS. Don't add preload unless you have a technical contact who has read the submission requirements, and you're certain every subdomain will always have a certificate. Most small business sites don't need it.

If something goes wrong

  • Visitors see a certificate error with no "continue" option. HSTS is working as designed, but your certificate has a problem. Fix the certificate. See SSL errors.
  • You need to turn HSTS off. Set max-age=0 and keep it live until visitors have loaded your site once. Browsers then forget the rule.
  • The header doesn't appear. mod_headers may not be active for that folder, or a caching plugin is serving old responses. Clear caches and check again. In WordPress, a security plugin may offer an HSTS switch instead. Use one place only, to avoid sending the header twice.

Was this helpful?

Still stuck? Ask us and we'll walk you through it.