Multiple GitHub Pages and custom domains via DNS
Asked Answered
K

3

85

I want to have one user page and multiple project pages hosted by GitHub Pages but available under ONE custom domain (with subdomains for each GitHub Pages repository, of course). So my goals are as follows:

As of my current understanding, GitHub Pages do only allow ONE CNAME resource record for a page (both user pages and project pages) defined in the CNAME file in the root of a Git repository. I already tried out many things (playing around with DNS records and header redirects at my domain provider EUserv, but I can only access my GitHub user pages under one URL (http://blog.florianwolters.de). I am aware that DNS changes can take up until two days.

Can somebody explain to me, how I can achieve the goals described above? I can not believe that this is not possible but I am also no expert for DNS, etc.

If the above is not possible: What is your suggested workaround? I do want to access all my GitHub pages under one domain (and the subdomains of that domain).

Resources

Kofu answered 21/5, 2012 at 13:14 Comment(2)
Not possible. See Multiple domains in CNAME file on My custom domain isn't workingColvin
This blog post details the issue. captainwhippet.com/blog/2014/05/11/blog-setup-details.htmlBradbradan
H
80

You can do it. Notice that all DNS CNAME entries point to the same host.

1: github.com/florianwolters/florianwolters.github.com

CNAME file content: blog.florianwolters.de

DNS CNAME: blog > florianwolters.github.com

2: github.com/florianwolters/pear/tree/gh-pages

CNAME file content: pear.florianwolters.de

DNS CNAME: pear > florianwolters.github.com

Hobnob answered 22/5, 2012 at 12:44 Comment(5)
OK, the file content of both CNAME files and the first CNAME resource records do already match your suggested values. I changed the second DNS CNAME record. I will report tomorrow if it works. Also, one part of my question remains: Which CNAME records do I have to create to reach blog.florianwolters.de via florianwolters.de and www.florianwolters.de? I can't make this work. Even a header redirect does not work?! Nontheless, thanks so far!Kofu
If you are using a top-level domain like florianwolters.de, you must use an A record pointing to 204.232.175.78. This way you will get a redirect to the www, wich is pretty standard. I think you have to create a separated www project as well. the only reamining problem is then how would you redirect from the www to the blog? this is need to be done ideally on server side, that is involving some kind of server side language/framework combo to run on the www subdomain, and in this case github can't help you much. examples: github.com/thoughtnirvana/www_redirectHobnob
Your answer was the solution to my problem. Now I can host as many projects as I want via subdomains. That's awesome! See my answer for a final clarification. I got it work server-side (at my domain registrar) with two simple header redirects. That's sufficient for my demands. The reason, this hasn't worked before was, that I deleted the default A resource records (pointing to an IP of my domain registrar). Hence the header redirects didn't work.Kofu
Is this still working? Looks like Github is now only supporting the gh-pages branch... that sound right?Bootery
Thank you very much, it's still working and it's amazing!Roof
K
6

You can either use one CNAME resource record or one A resource record together with GitHub Pages.

So, in conclusion one have to decide:

  • Either you use example.org and www.example.org (replace the existing A record with 204.232.175.78) ...
  • ... or a subdomain, e.g. blog.example.org (create a new CNAME record with <username>.github.com).

Now, you have to choose how-to map from one (sub)domain to another:

  • If using the first you can use redirects by utilizing HTTP headers from the desired subdomain(s) to example.org.
  • If using the latter you have to use header redirects from example.org and www.example.org to the desired subdomain(s).

Also, see GitHub Pages Help for help and my GitHub Pages repository for an example CNAME file.

Edit: GitHub Pages added a detailed page that describes how-to set up a custom domain here.

Kofu answered 26/5, 2012 at 13:32 Comment(2)
Can you clarify some more: What do you mean with: "... use header redirects from the desired subdomain(s) to example.org." Do you mean to create CName record on your dns? DNS CNAME pear --> example.org ?? OR DNS CNAME pear --> userename.github.com ??Mure
@elviejo: I believe what he meant was to use redirects using HTTP headers.Grief
H
1

You can only have one CNAME resource record for a page (both user pages and project pages) defined in the CNAME file in the root of a Git repository.

You can circumvent this by creating a CNAME record for your host(pear) in your DNS settings pointing to florianwolters.github.com, and making a entry in your CNAME file in repository for pear.florianwolters.de

Haemoglobin answered 26/4, 2018 at 8:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.