How to redirect non ssl (http links) traffic to SSL (https links)

Our Level I techs often gets tickets like how to make http:// or http://www. redirect to https:// or https://www. Often the answer is simple, but for the newbies and yours use, I am putting it here.

First requirement is to have an SSL certificate installed. Add the following lines in a .htaccess file:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

I assume when you directly access https://www.domainname.com , the site loads fine.

Related posts:

  1. Redirecting a domain to a subfolder using .htaccess.
  2. Error in Drupal while enabling clean URL
  3. HTTP 405: The HTTP verb used to access this page is not allowed
  4. How do I redirect a given port on a given IP address to a different port on a different host or network

Comment Form

About this blog

This blog, acts as a knowledge repository for the world and is unofficial! Anything we find interesting in the cyber world will go here. Most cases, this blog will reflect the happiness of our staff in reaching successful solution to an issue (s)he worked on. A reference for other fellow SAGEs who come across similar issues later