Force an SSL-connection to your website with .htaccess


You can force the visitors of your website to view the site with https:// (an SSL-connection)
To make that possible you need: 
  • a signed SSL-certificate (either your own certificate or one you bought at EDIS GmbH)
  • you will have to put on the two following rewrite-rules in a .htaccess file in the document-root of your website.

First option:

RewriteEngine on
RewriteCond %{ENV:HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Second option:

RewriteEngine on
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
 

Add Feedback