How do you enable HTTP Strict Transport Security (HSTS)?
HTTP Strict Transport Security (HSTS) tells browsers to only communicate with your website over HTTPS. This prevents protocol downgrade attacks and cookie hijacking by ensuring all connections use SSL/TLS.
Enabling HSTS
Section titled “Enabling HSTS”Add the following to your site’s .htaccess file:
Header always set Strict-Transport-Security "max-age=31536000"This tells browsers to only use HTTPS when connecting to your site for one year (31,536,000 seconds).
Including subdomains
Section titled “Including subdomains”To apply HSTS to all subdomains as well:
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"HSTS preloading
Section titled “HSTS preloading”To submit your domain to the HSTS preload list (which hardcodes the HTTPS requirement into browsers), use:
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"