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 ‘’.

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 ->

I got the ‘www.’ prefix for the website working but the redirects were still not working as they should. If someone visited then it would redirect to but not to

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


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.