Can github pages CNAME file contain more than one domain?
No, this is not possible. See the GitHub Help docs that explain this:
Ensure you only have one domain listed in your CNAME file. If you wish to have multiple domains pointing to the same Pages, you will need to set up redirects for the other domains. Most domain registrars and DNS hosts offer this service to their customers.
Only one DNS record is needed to point reggi.com OR www.reggi.com to username.github.io.
Github automatically points both to username.github.io
With the above set you can reach username.github.io/blog at:
blog.reggi.com (with CNAME file containing blog.reggi.com) or reggi.com/blog or www.reggi.com/blog
or even
blog.reggi.com/blog (with CNAME file containing blog.reggi.com)
Hope this helps. It was beyond me for a while.
Here is one approach that is a Github-only solution using an HTML redirect.
- Create an extra repository
- Configure it to use Github Pages with the additional domain
- Add an an
index.html
file with the following contents
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Redirecting to https://example.com</title>
<meta http-equiv="refresh" content="0; URL=https://example.com">
</head>
<link rel="canonical" href="https://example.com">
</html>