How to make a domain point to a sub-folder of a GitHub Page site?
Asked Answered
B

2

6

I've got my GitHub Page sites setup like this:

myname.github.io
    + project1
    + project2

So when I go to myname.github.io/project1, it opens project 1, etc.

What I would like is setup a custom domain eg. myproject2.com and point that to myname.github.io/project2 only, so if I go to myproject2.com it would serve the content of "project2".

I've read the GitHub Page doc but they don't mention this particular case, so I'm not sure if it can be done. Any idea?

Balk answered 27/7, 2017 at 18:5 Comment(1)
This might be the answer you are looking for - https://mcmap.net/q/1920210/-how-to-point-a-custom-sub-domain-to-a-sub-directory-of-a-github-repository Maintaining a gh-pages branch where you'd use subtree to push your builds.Dulcie
D
0

DNS records cannot contain / in the name and in that way cannot point to subfolders in GitHub repositories.

An alternative approach is to create a separate branch (eg. gh-pages) where you push only the project's build or dist folder. In your case - project2. The Terminal command to do this would be git subtree push --prefix project2 origin gh-pages while you are on main branch. Remember to correctly point to gh-pages branch in Settings (Settings -> Pages -> Build and deployment -> Branch)

Dulcie answered 11/1 at 21:56 Comment(1)
This question is nearly seven years old. Since then, questions about DNS are now off topic. Hover over his dns tag for more info. Do not answer off topic questions. Vote to close instead.Erwinery
C
-1

Go to your repo for project1, click Settings tab, scroll down to "GitHub Pages" and look at the "Custom domain" section. The steps for setup are linked from there (https://help.github.com/articles/using-a-custom-domain-with-github-pages/)

To clarify, project1 and project2 should be in separate repositories for this to work.

Your domain name registrar / DNS provider should be able to provide support for creating the DNS records you need to set this up.

Custom domains can be setup per repo, including but not limited to the root GitHub pages repo for your account (yourusername.github.io)

Colcothar answered 27/7, 2017 at 18:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.