Redirecting GitHub Pages to HTTPS with CloudfLare
home / dev / redirecting github pages to https with cloudflare
Updated: 2017-04-24
Your GitHub repo settings have an Enforce HTTPS
option under the GitHub Pages section, but that won’t work with custom domains. You can instead take advantage of Cloudflare’s free SSL certificate.
After configuring everything you will perhaps notice that visits to http://example.com does not redirect to https://example.com. To overcome this, you can go to Cloudflare’s Page Rules page for which everyone is given 3 free page rules.
Click the Create Page Rule
button, write your website URL (e.g. http://example.com/*) in the first textfield, click Add a Setting
. Select Forwarding URL
setting and set Status Code to 301 - Permanent Redirect
, and enter your website URL with HTTPS prefix and $1 suffix (e.g. https://example.com/$1) in the destination URL textfield.
After clicking Save and Deploy
, visits to http://example.com/path will be redirected to https://example.com/path.
The picture below shows how it has been setup to redirect all HTTP traffic to HTTPS for any page on maike.me:
This will of course also work with websites hosted anywhere else, such as the Google Cloud Platform, AWS, etc.