DEV Community

loading...
Cover image for HTTPS Domain Forwarding for Free via GitHub Pages

HTTPS Domain Forwarding for Free via GitHub Pages

alvinqingxing profile image Alvin Lim ・2 min read

This week I decided to move my homepage from alvinlim.me to alvinlim.dev.

I remembered that my domain name registrar offered a free URL redirect service, and I decided to use that forward alvinlim.me to alvinlim.dev. While that worked for http://alvinlim.me, clicking https://alvinlim.me instead threw an SSL error.

Basically, for the URL redirect of https://alvinlim.me to work, https://alvinlim.me first had to be recognized by the browser as a valid website, and this meant it had to have a valid SSL certificate attached to it.

This meant I had to set up a website for https://alvinlim.me, attach a SSL certificate to it, and configure the HTML to redirect the browser to https://alvinlim.dev. 😅

This raised the question -- wouldn't setting up the website and SSL certificate be expensive? That's when I remembered that I could quickly set up a free website on GitHub Pages, connect it to my alvinlim.me domain, and GitHub Pages would even provision and attach an SSL certificate to it for free! Since I already had the alvinlim.me domain, I decided to go with this option.

So I created a new repo on GitHub which hosts an index.html file which is empty except for the important meta refresh tag which redirects the browser to the new URL:

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="refresh" content="0; URL=https://alvinlim.dev">
  </head>
  <body></body>
</html>
Enter fullscreen mode Exit fullscreen mode

I next created a GitHub Pages site from that repo and attached my domain to it. In the GitHub Pages settings I then selected the "Enforce HTTPS" option.

With all this in place, clicking https://alvinlim.me no longer throws an SSL error but instead correctly redirects the browser to https://alvinlim.dev.

Discussion (2)

pic
Editor guide
Collapse
sunnysingh profile image
Sunny Singh

Nice! You could also set up Cloudflare in front of your old domain which provides free SSL, and you could then have a real server redirect.

I do like the simplicity of GitHub Pages though with the meta redirect.

Collapse
levirs565 profile image