HTTP to HTTPS Redirect via HTAccess

, , , ,

So to have an entire site get redirected from HTTP to HTTPS you can use the following redirect code within the .htaccess file.

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

and to go in reverese

RewriteEngine On 
RewriteCond %{SERVER_PORT} 443 
RewriteRule ^(.*)$ http://www.example.com/$1 [R,L]

Doing it these ways allows you to stop the attempted loading of a bad SSL certificate before it happens.

Skills

Posted on

April 14, 2017

Submit a Comment

Your email address will not be published. Required fields are marked *