Skip to content
xYnta
Go to websitexynta.com
Search
EN

Enabling HSTS

Updated on

HSTS (HTTP Strict Transport Security) tells your visitors' browsers that your website can only be reached over a secure connection (HTTPS). From then on the browser no longer uses a plain HTTP connection, not even when someone types http://. This protects against man-in-the-middle attacks. You first enable HSTS with a short period (5 minutes) and only extend it once everything works.

Before you start

  • Your website works fully over HTTPS, with a valid SSL certificate. See Setting up a free SSL certificate.
  • All scripts, stylesheets, images and other resources on your website load over https://.
  • Your website redirects http:// to https://: a browser only adopts HSTS after a visit over HTTPS. In DirectAdmin this is Force SSL with https redirect on the same page as below; in Plesk it is the option Redirect visitors from HTTP to HTTPS via a SEO friendly 301 redirect in the hosting settings of your domain.

Web Hosting (DirectAdmin)

Also for Reseller Hosting.

  1. Log in to DirectAdmin via Single Sign-On from Mijn xYnta, or at https://yourdomain.nl:2222.
  2. Under Account Manager, click Domains and then yourdomain.nl. The Modify Domain screen opens.
  3. Under HSTS, tick Enable HTTP strict transport security.
  4. At Max-age for HSTS header, choose 5 minutes, and leave Include subdomains off.
  5. Click MODIFY.

Note: DirectAdmin adds preload to the header itself: max-age=300; preload. At 5 minutes this has no effect; if you later extend it to a year with Include subdomains, the header meets the requirements of the preload list (see below).

WordPress Hosting (Plesk)

  1. Log in to Plesk at https://whs1.srvnl.nl:8443. You can find your server name in How can I find the server name of my hosting package?
  2. On the left, click Files and then the httpdocs folder.
  3. If there is no .htaccess yet, click the blue plus button, choose Create File, enter .htaccess under File name and click OK.
  4. Click the name .htaccess. The file opens in the Code Editor.
  5. Put Header set Strict-Transport-Security "max-age=300" at the top of the file, on a line of its own. If there is a block # BEGIN WordPress … # END WordPress, put the line above that block: WordPress rewrites everything in between.
  6. Click Save.

Then: extending the period

  1. Extend the period

    DirectAdmin: at Max-age for HSTS header, choose 1 year and click MODIFY. Plesk: change max-age=300 in the line to max-age=31536000 (one year) and click Save.

  2. Only include subdomains if they all have HTTPS

    If all your subdomains (including mail., webmail. and any you created yourself) work over HTTPS, you can include them. DirectAdmin: tick Include subdomains. Plesk: make it max-age=31536000; includeSubDomains.

Tips

  • Test HSTS on a subdomain first, and write down what you change so you can find it again later.
  • Switching HSTS off does not work immediately: a browser that saw the header earlier keeps requiring HTTPS until the old period is over. If you use the line in .htaccess, first set max-age=0 and leave that line in place until the old period has expired.

HSTS preload list

The HSTS preload list is a list built into browsers such as Chrome, Firefox and Safari. A domain name on that list always opens over HTTPS, even on the very first visit: the browser skips the HTTP request. Getting off the list is difficult, so only submit your domain name after thorough testing, when all your subdomains have HTTPS and you intend to use HTTPS permanently. The header must then contain at least one year, all subdomains and preload:

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

More information and submission: hstspreload.org.

Related articles