htaccess – 301 Redirect Website From http to https

htaccess fun

More and more websites are making the move from http to https, primarily because of Google’s announcement back in August 2014, where they said websites with SSL (i.e. secure connection) will benefit from a slight boost in search engine rankings.

Many have made the move, yet failed to notice any difference in rankings. Perhaps the boost is so lightweight that it’s extremely difficult to track. In any case, I don’t see anything wrong with getting an SSL certificate, even if your website isn’t dealing with sensitive data or necessarily going to benefit from a boost, because it ultimately does make a website online essay writing service uk more secure when transferring data, and that’s always a good thing.

The code

The following code will 301 redirect all http URLs to https. For example http://www.example.com will redirect to https://www.example.com

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


  1. Juan Carlos spoke on 09/09/2015


    Question: When should I put this code? (file, directory, etc.). Thanks!

  2. Maruf spoke on 15/10/2015

    Hi Juan,

    The code should go at the top of your .htaccess file, which should go in the root directory.

Leave a reply

Your email address will not be published. Required fields are marked *