Redirect HTTP to HTTPS in Apache

Create a .htaccess file in the web server root with the following content to automatically redirects visitors to HTTPS

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