Redirect HTTP to HTTPS but this time with the WWW!

Well, I was not a 100% happy with the way the redirect was working when I initially set it up.

Any HTTP traffic heading to the site would get redirected to HTTPS but only if someone visited the link by using the naked domain ‘dipen.co.uk’.

Plus, I had a little bit of tinkering to do to the site as well. I wanted the ‘www.’ prefix working. Unfortunately if the ‘www.’ prefix was used, an error would appear. Something to do with Cloudflare but that is a topic for another post. By the way, if you don’t use Cloudflare, I highly recommend it! Link -> https://www.cloudflare.com/

I got the ‘www.’ prefix for the website working but the redirects were still not working as they should. If someone visited http://dipen.co.uk then it would redirect to https://dipen.co.uk but not to https://www.dipen.co.uk

Bit of searching and I came across this lovely snippet on StackOverflow:

Source: https://stackoverflow.com/questions/13977851/htaccess-redirect-to-https-www

It works like a charm! The balance in the universe has been restored! Yay!

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.