Search code examples
dnsgithub-pageswebsite-hosting

How can I point multiple domain names to the same GitHub Pages site?


This seems like it should be a trivial task but isn't proving to be one for me...

How should I go about pointing multiple domain names to the same GitHub Pages hosted site?

Example:

I have created an account named test on GitHub and created a repository test.github.io

I bought test.com

I configured test.com's DNS as below

I have told GitHub Pages to enforce https and look out for custom domain test.com

My site is now live on test.com and www.test.com, woohoo!

DNS Config for test.com:

A @ 185.199.108.153 (github's nameserver)

A @ 185.199.109.153 (github's nameserver)

A @ 185.199.110.153 (github's nameserver)

A @ 185.199.111.153 (github's nameserver)

CNAME @ www.test.github.io (for www redirect)

I would ALSO like example.com (and a few other domains, foo.com, bar.com and foobar.com) to redirect to test.com

How do I do this?
With an apache server, this would be easy, be GitHub Pages only supports static sites.

Any ideas?

As always, thanks for any suggestions!


Solution

  • The ideal place to have this redirect is your DNS provider. You can redirect foo.com, bar.com, etc. or whatever you want to test.com. Alternatively, if you happen to use Cloud Flare, forwarding can easily be setup from there too.

    But if you don't want to do that and insist on using Github only, refer to this answer. What you can do in this case is create another repository (other than test.github.io) with same contents and link it to another domain such as foo.com. You can use Github Actions or something to sync your changes from main repo to the others.

    Of course, the only drawback of this method is that for every domain you want to link, you'll have to create an additional github repo.