Redirect all HTTP requests to HTTPS automatically using .htaccess and web.config

Redirect HTTP to HTTPS automatically with Linux-based and Windows. Using the following code in your .htaccess (Linux & cPanel) and web.config (Windows) file automatically redirects visitors to the HTTPS version of your site.
Linux & cPanel: Linux-based accounts use .htaccess files to handle redirection.
  RewriteEngine On
  RewriteCond %{HTTPS} !on
  RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
{OR}
  RewriteEngine On
  RewriteCond %{HTTPS} off
  RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Windows: Windows-based accounts use web.config files to handle redirection.