Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitHub Pages: Redirect custom.domain.tld > user.github.io/project/

Tags:

github-pages

As the subject says, I'd like to have my custom domain redirect to a specific project's gh-pages branch.

I can easily get the standard behaviour:

  • custom.domain.tld > user.github.io (Where the static content lives in github.com/user/user.github.io/ master branch)
  • custom.domain.tld/project/ > user.github.io/project (Where the static content lives in github.com/project/ gh-pages branch)

But I cannot figure out how to get this:

  • custom.domain.tld > user.github.io/project (Where the static content lives github.com/user/project/ gh-pages branch)

I very much appreciate pointers.

like image 763
adam Avatar asked Feb 07 '14 02:02

adam


People also ask

How do I redirect a custom domain to GitHub?

On your site's repository, click the settings tab . Under custom domain, type your custom domain and save. GitHub will automatically create a commit with a CNAME file at the root of your repository. Visit the dashboard provided by your domain provider and add a CNAME record pointing to your subdomain.

Can you use a custom domain with GitHub Pages?

You can customize the domain name of your GitHub Pages site. GitHub Pages is available in public repositories with GitHub Free and GitHub Free for organizations, and in public and private repositories with GitHub Pro, GitHub Team, GitHub Enterprise Cloud, and GitHub Enterprise Server.

How do I redirect a GitHub website?

The redirect is accomplished with a <meta> tag. By setting the http-equiv attribute to refresh and the content attribute to 0; URL=https://example.com/ we will redirect the user to 'https://example.com/'.


1 Answers

If your custom.domain.tld currently points to username.github.io, you'll need to remove the CNAME file from your user.github.io repository's Master branch. Then, add the same CNAME file (with contents custom.domain.tld) to your Project repository's gh-pages branch. If you've already set up DNS properly for your user.github.io repository, then you won't need to make any changes there, the new CNAME settings on GitHub will take care of it.

One note: when you assign a custom domain (eg custom1.domain.tld) to a User Pages repository, all Project Pages in that User's account will inherit their respective custom1.domain.tld/project address, as well as any directly assigned domain (eg custom2.domain.tld).

For example, I have:

  • www.nicksuch.com > nicksuch.github.io
  • www.openkentucky.org > nicksuch.github.io/openkentucky (also accessible at www.nicksuch.com/openkentucky)
  • DNS settings: CNAME - www > nicksuch.github.io (same for both domains, even though one is a User Page and the other is a Project Page)

More in GitHub's Setting up a custom domain with Pages.

like image 194
nicksuch Avatar answered Sep 29 '22 15:09

nicksuch