HSTS – How to Use HTTP Strict Transport Security

Updated on November 09, 2017

Ensuring security is setup correctly for your WordPress site is very important, especially when it comes to protecting yourself from hackers. There are numerous different enhancements and best WordPress security practices you can implement to ensure that your site is locked down. If your WordPress site runs over HTTPS, then one of the enhancements we recommend implementing is the HSTS security header, as it can help prevent man-in-the-middle attacks (MitM) and cookie hijacking.


What is HSTS?

HSTS stands for HTTP Strict Transport Security and was specified by the IETF in RFC 6797 back in 2012. It was created as a way to force the browser to use secure connections when a site is running over HTTPS. It is a security header in which you add to your web server and is reflected in the response header as Strict-Transport-Security. HSTS is important because it addresses the following issues:

  • Any attempts by visitors to use the unsecured version (HTTP://) of a page on your site will be automatically forwarded to the secure version (HTTPS://).
  • Old HTTP bookmarks and people typing the HTTP version of your site are open you up to man-in-the-middle attacks. These are attacks where the attacker alters communication between parties and tricks them into thinking they are still communicating with each other.
  • Doesn’t allow for the overriding of the invalid certificate message which really, in turn, protects the visitor.
  • Cookie hijacking: This can occur when someone steals a session cookie over an unsecured connection. Cookies can contain all sorts of valuable information such as credit card information, names, addresses, etc.

How to Add HSTS to Your WordPress Site

Technically you are adding HSTS to the web server itself, which is then applied to HTTP requests to your WordPress site. Typically a 301 redirect is added when doing a redirect from HTTP to HTTPS. Google has officially said that you can use both 301 server redirects as well as the HSTS header together.

Although our systems prefer the HTTPS version by default, you can also make this clearer for other search engines by redirecting your HTTP site to your HTTPS version and by implementing the HSTS header on your server. Zineb Ait Bahajji, Google Security Team

There are different types of directives and or levels of security that can be applied to the HSTS header. Below is the most basic one which uses the max-age directive. This defines the time in seconds for which the web server should only deliver through HTTPS.

Enable HSTS in Apache

Add the following code to your virtual hosts file.

Header always set Strict-Transport-Security "max-age=10886400

Enable HSTS in NGINX

Add the following code to your NGINX config.

add_header Strict-Transport-Security "max-age=10886400

If you’re a Kinsta client and want to add the HSTS header to your WordPress site you can open up a support ticket and we can quickly add it for you.

Preload HSTS

There is also HSTS preloading. This is basically getting your website and or domain on an approved HSTS list that is actually built into the browser. Google officially compiles this list and it is utilized by Chrome, Firefox, Opera, Safari, IE11 and Edge. Submit your site to the official HSTS preload list.

preload hsts

However, you must meet some additional requirements to be eligible.

  1. Server must have a valid SSL/TLS certificate.
  2. Redirect all traffic to HTTPS.
  3. Serve HSTS on the base domain.
  4. Serve all subdomains over HTTPS, specifically including the www subdomain if it exists.
  5. Expiry must be at least eighteen weeks (10886400 seconds)
  6. The includeSubdomains token directive must be specified
  7. The preload token directive must be specified.

To do this it requires adding the additional subdomains and preload directives to your HSTS header. Below is an example of the updated HSTS header.

Strict-Transport-Security: max-age=10886400; includeSubDomains; preload

Verify HSTS Header

There are a couple easy ways to check if the HSTS is working on your WordPress site. You can launch Google Chrome Devtools, click into the “Network” tab and look at the headers tab. As you can see below on our Kinsta website the HSTS value: “strict-transport-security: max-age=31536000” is being applied.

strict transport security http response

You can also scan your WordPress site with a free online tool like securityheaders.io which will let you know if the strict-transport-security header is being applied or not.

scan security headers

HSTS Browser Support

According to Caniuse, browser support for HSTS is very strong at over 80% globally and over 95% in the United States. Support for HSTS in IE11 was added in 2015 and currently the only modern browser that doesn’t support it is Opera Mini.

hsts browser support

We also recommend checking out this article from Tim Kadlec on HSTS and Let’s Encrypt.

If you enjoyed this tutorial, then you'll love our support. All Kinsta's hosting plans include 24x7 support from our veteran WordPress developers and engineers. Chat with the same team that backs our Fortune 500 clients. Check out our plans
Was this article helpful?
No, or there was something off

Hand-picked related articles

Use WordPress?

Use WordPress?

Join 20,000+ others who get our FREE weekly newsletter with WordPress tips on how to drive more traffic and revenue to your business!


You have Successfully Subscribed!

Send this to a friend