Skip to content

Latest commit

 

History

History
35 lines (18 loc) · 1.91 KB

custom-subdomain-github-pages.md

File metadata and controls

35 lines (18 loc) · 1.91 KB

Setting up a custom subdomain for a GitHub Pages site

This is so much easier than I was expecting it to be.

I launched my new Datasette Lite project (background) using GitHub Pages - originally hosted here:

https://simonw.github.io/datasette-lite/

Shortly after launching I realized that the project deserved its own vanity subdomain. I wanted to use lite.datasette.io for this.

GitHub Pages makes this really easy.

I started by pointing the CNAME for lite.datasette.io at simonw.github.io - I use Vercel for the DNS for that domain, so I set this up in their interface.

Then I used the Pages tab in the "settings" interface for the GitHub repository and told it about my new domain.

GitHub wrote a file called CNAME directly into the root of my repository for me containing just lite.datasette.io

This started working over HTTP straight away - it took a few more minutes for the Lets Encrypt certificate to be issued for it, at which point https://lite.datasette.io/ started working too.

I then used the "Enforce HTTPS" option to ensure any hits to http://... were redirected to https://

Screenshot of the GitHub interface for setting the domain, showing the Enforce HTTPS checkbox

Redirects

GitHub Pages set up redirects from the old https://simonw.github.io/datasette-lite/ site to the new one without me even asking them to.

The redirects preserve both query string parameters AND fragment hashes, which means that this old URL continues to work after the move:

https://simonw.github.io/datasette-lite/#/fixtures?sql=select+sqlite_version%28%29

It redirects to:

https://lite.datasette.io/#/fixtures?sql=select+sqlite_version%28%29