For my website's .htaccess I currently have:

RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

So that when someone visits the page over http they get a 301 and then connect over SSL/TLS. However, this still opens users up to MITM attacks via sslstrip. I noticed that if I go to http://facebook.com in my network log the request gets changed to https://facebook.com before a response comes back, preventing a MITM attack. I was wondering how this was achieved so I can force SSL/TLS better.


1 Answer 1


Facebook achieves this with a HTTP Strict Transport Security (HSTS) policy.

This is delivered over HTTPS and informs the browser to automatically "rewrite" HTTP requests to HTTPS for that domain. The max-age parameter specifies how long the browser will honour the policy for.

It is also possible to list your site in the HSTS preload list. This list is shipped with browsers. The advantage of the list is that the site does not require the first (insecure) visit to be made in order for the policy to be set.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .