Enabling HTTPS using .HTACCESS and Apache

You have a website but you can’t get it to automatically show https even when you have an https certificate installed.

Believe it or not you are half way there if you have your https certificate installed. Now you just need to let apache know that you want to show HTTPS instead of HTTP. The code at the bottom of this blog will force HTTP to HTTPS.

All websites can benefit from having a HTTPS certificate installed you don’t need to have a ecommerce site for this to have a benefit.

Why would you use HTTPS?

There are a few reasons why HTTPS is Good

  1. Google admitted they give a slight boast for HTTPS.
  2. Your website will be more secure and also looks much more trusting.
  3. There is also the case as well that about 60% of the top positions in Google have HTTPS.
  4. You will get a nice pad lock icon in Chrome instead of showing insecure.
  5. We really don’t want the http version to index with Google because it will show up as duplicate content.

This works fully for apache and Cpanel. You should get no problems if you are using a CMS such as WordPress or Drupal. It is also noting this will also work on Shared hosting as well as VPS.

We are going to use a file called .httacess to simply get the server to automatically force https.

Warning messing with this file can really make your website turn green make sure you back your .htaccess file up before adding the code bellow.

It is better to be safe rather than sorry.  

If you run into problems you can simply just re-upload the backup version.

Force HTTP to HTTPS Code

# add https

RewriteEngine On

RewriteCond %{HTTPS} off

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

# end add https

The code above is simply telling the server that if you land on the HTTP version of the website to go straight to the HTTPS version.

With my website as an example

If you were to land on http://digitalgrowtharchitects.co.uk/ it will now automatically go to https://digitalgrowtharchitects.co.uk/

When you are adding the code in your .htaccess make sure it is towards the top else you may well run into problems.

Make sure you make a backup of your original .htaccess before you insert the code

Test your new code with your website and check that you are not getting no 500 errors. If you do run into problems let your host know.  Show them the code that you are using and what you are trying to do.

You can easy revert back by using your backup version

If this is all confusing not to worry I will be doing either a workshop version of this blog or a video very soon.

Posted in

Kevin Blumer

Digital Business Strategist & Developer SEO & Digital Marketing Wizard Expert in Implementation| Empowering Success with Innovative Digital Strategy & Development