anmonteiro Code ramblings

Custom subdomains in GitHub project pages

If you host your website, blog or project pages in GitHub Pages, you might already be rolling your own custom domain. However, while there is plenty of information on how to set that up, what you might not know is that you can also set up a custom subdomain for your project pages.

Note: when you use your own domain (e.g. mydomain.com) with GitHub Pages, you get your project pages under that domain for free (e.g. myusername.github.io/pjname will also be available under mydomain.com/pjname)

So, if you’d like to publish your project page under pjname.mydomain.com, even though it will live under mydomain.com/pjname anyway, but you might just prefer it this way), simply follow these steps:

  1. Add a CNAME file to your project’s repository. The content of this file must be a single line specifying the bare subdomain for your project’s custom subdomain (e.g. pjname.mydomain.com).
  2. In your DNS provider’s settings, create a new CNAME record that points pjname to either the root (usually denoted by @), if you have previously set up an apex domain, or to myusername.github.io if you’ve set up a custom subdomain. It should look something like this:

And that’s it! After a few moments the changes should take effect. Thanks for reading!

If you have any questions or suggestions, be sure to reach me on Twitter.