How to Redirect HTTP to HTTPS using .htaccess File

HTTP to HTTPS geekletters

You can easily redirect your visitor form http version of your website to https version of your website. This can be done using apache mod_rewrite. This technique makes sure that the visitor your website always goes to the https version of the website or part of your website you have implemented SSL for your website.

This method is better than SSLRequireSSL  because people often forget to write https in the url .

Before setting up to redirect your website form http to https please through the following check-list.

  1. Ensure the SSL certificate is already install on your website and your website is accessible at
  2. Make sure mod_rewrite is enabled in Apache
  3. Create a .htaccess file in your web server root directory, and write the following code on it.

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{SERVER_NAME}/ [R,L]