Skip to content
Security2 min read

What is HSTS?

Short answer

HSTS (HTTP Strict Transport Security) is a header a site sends over HTTPS asking the browser to connect only over HTTPS for a period set by max-age. After that, the browser upgrades any http link to https itself before sending the request, and won't let users click through certificate errors.

ArabyHost teamLast updated: ShareWhatsAppXLinkedIn
Contents
  1. How it works
  2. The directives
  3. Example: adding it with .htaccess
  4. Risks and common mistakes
  5. On ArabyHost

Even with an http-to-https redirect, that first http request travels in the clear. On public Wi-Fi an attacker can intercept it and suppress the redirect, keeping the visitor on an unencrypted version without them noticing. This is called SSL stripping, and HSTS is the cure.

How it works

  1. A user visits your site over HTTPS and receives the header:

    Strict-Transport-Security: max-age=31536000; includeSubDomains
  2. The browser records that this domain is HTTPS-only for 31536000 seconds, one year.

  3. On later visits the browser rewrites any http:// link to https:// internally, before sending anything.

  4. If there’s a certificate error, the browser doesn’t offer a “proceed anyway” button.

The directives

Directive Meaning
max-age How long to remember the policy, in seconds
includeSubDomains Apply the policy to every subdomain
preload Ask for the domain to be built into browsers’ preload list

Example: adding it with .htaccess

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

Start short, at 300 (five minutes), check that the site and all subdomains work over HTTPS, then raise it to a day, then to a year.

Risks and common mistakes

  • includeSubDomains with a subdomain that has no certificate, such as an internal panel on http: browsers can no longer reach it.
  • Rushing into preload: removal from the list is slow, and the list requires at least a year’s max-age plus includeSubDomains.
  • An expired certificate with HSTS: visitors can’t bypass the warning at all, so renewal must be automatic.
  • Testing changes on your own machine: the browser remembers the policy even after you remove the header. In Chrome you can delete it for one domain at chrome://net-internals/#hsts while testing.

On ArabyHost

The free certificate is issued and renewed automatically through AutoSSL and Let’s Encrypt, which is the key requirement for using HSTS safely. Add the header in the .htaccess file in your site’s folder; the LiteSpeed web server supports these directives. First turn on the redirect as in the force HTTPS guide, then add HSTS once you’ve confirmed every subdomain has a valid certificate.

FAQ

Does HSTS replace the 301 redirect to HTTPS?

No. The browser only learns the HSTS policy after a first visit over HTTPS, so you still need the 301 redirect for that first visit; HSTS handles the ones after.

How do I undo HSTS if something breaks?

Send the header with max-age=0 and browsers drop the policy on their next HTTPS visit. If the domain is on the preload list, getting it removed takes a long time.

Does HSTS affect SEO?

It isn't a direct ranking factor, but it replaces a server redirect with an in-browser one, so pages open slightly faster for returning visitors.

Useful? Share it with someone who needs it:WhatsAppXLinkedIn

Read next

Ready to put your idea online?

Fast, isolated hosting, support that understands you, and an AI assistant that fixes problems with you.