84

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

2

3 Answers 3

80

You can do it. Notice that all DNS CNAME entry 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

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! May 23, 2012 at 12:39
  • 2
    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_redirect
    – marfalkov
    May 23, 2012 at 19:00
  • 2
    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. May 26, 2012 at 13:45
  • Is this still working? Looks like Github is now only supporting the gh-pages branch... that sound right? Sep 17, 2013 at 20:32
  • 1
    Thank you very much, it's still working and it's amazing!
    – Kalitine
    Dec 26, 2015 at 15:42
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.

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 ??
    – elviejo79
    Apr 17, 2013 at 20:26
  • 1
    @elviejo: I believe what he meant was to use redirects using HTTP headers.
    – damd
    May 25, 2013 at 22:18
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.