Force Your Website to Use SSL via .htaccess

This post is old. It may contain broken links, missing images and incorrect information.

SSL stands for Secure Sockets Layer – it the method by which the connection between your browser and the website you’re visiting is encrypted, ensuring information can be passed securely between the two.

Traditional SSL was only used to encrypt connections where sensitive data was passed – login forms for instance. But a while ago Google announced that SSL would become a search engine optimisation ranking factor for websites resulting in use of SSL becoming far more common place.

Users are now comfortable recognising the padlock symbol which is activated in most browsers when connecting to a website requesting an SSL connection. Also, more and more websites are allowing users to register for accounts and submit potentially sensitive information via contact forms and so on.

Add to this the fact that many hosts are now offering SSL as standard – particularly with the advent of Let’s Encrypt – and it’s easy to see why ensuring your site is running behind an encrypted https:// connection makes good business sense.

Add These Lines To Your .htaccess File

Forcing your website to use an SSL connection is simple. If your web server is running Apache, you can just add this to your .htaccess file:

RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://DOMAINNAME.co.uk/$1 [R,L]

Don’t forget to update it with your actual domain name. Also, you’ll want to check your SSL certificate it active before applying this change, otherwise visitors may be shown a warning that will prevent them from easily accessing your website.

Jack Barber, freelance web developer based in Whitby, UK

Written By

I'm a freelance web developer based in Whitby, UK. I built my first website using GeoCities, and learned to write HTML and CSS using Notepad. Web technology has come a long way since then, as have my web development skills!

These days I love helping my clients make the most of the internet. I provide design, development, marketing and IT support services, forming long-term partnerships with my clients.

Connect With Me

Posted in Uncategorized