How to redirect HTTP to HTTPS Using .htaccess

Force to serve securely using HTTPS

The following forces any http request to be rewritten using https. This code can be used on any website. For example, the following code forces a request to to load It also forces directly linked website resources (javascripts, css, images etc.) to use https:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
Header always set Content-Security-Policy "upgrade-insecure-requests;"

Forcing All Pages to use HTTPS (Alternative)

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