After enabling SSL for a domain it is a good idea to redirect non-HTTPS URLs to HTTPS so if a visitor omitted the https:// prefix we would add it automatically.

In this post we are going to see how to preprend the https:// at the start of a URL using Apache web server .htaccess file and 301 redirect.

Copy following lines and paste it into .htaccess file in your webserver root folder.

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