Tips and Tricks

Force http to https

Aug 22, 2021

When you use HTTPS instead of HTTP the communications between your browser and your website is encrypted via an SSL (Secure Socket Layer).

In order your website to load securely, you must make sure that the URL it is prefixed with HTTPS instead of HTTP. This can be accomplished by different ways. Below we have a method through the .htaccess. So add the code to .htaccess and you are done.


#Force http to https:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]