Search code examples
github-pagescname

Why is CNAME file needed in github pages repository even I have the CNAME record at DNS provider?


I'm confused why CNAME file is also needed in my github pages repository? Why CNAME needs to be done twice at my domain provider and github pages?

How the things works together?


Solution

  • I did some further thinking, I think glglgl's answer doesn't answer my question. Because In my domain provider: I've added a CNAME Record like this: enter image description here
    when the request comes to github, github should have enough information to know which user's github page to deliver, right ? It's obvious the request is to get the xxuser's github page.

    Then why github page requires an additional CNAME file? The reason, I think, is that it gives the power to the owner of the repository to control what custom domain is allowed to link to the repository website. If a custom domain which is not in the CNAME file links to github page, there's going to be 404 error page shown from github. That means only the custom domain the owner put in the CNAME file can be linked, which obviously would be a domain owned by the owner of the repository.