Github 用户页面和自定义域问题
Github User Pages and Custom Domain Issue
我认为有几个问题与 github 页有关。
首先,当尝试通过将 repo 命名为与我的用户名相同来创建我的用户页面时,我希望 url 是这样的 myusername.github.io
。相反,它看起来像这样 myusername.github.io/myusername
.
我一直在通过命名我的存储库 myusername.github.io
来解决这个问题,它产生正确的 URL.
现在,我想用这个用户页面创建一个自定义域。我可以通过上述解决方法使用我的自定义域,但这现在会影响所有其他使用 github 页面的存储库。例如,我将 myusername.github.io
设置为使用 mycustomdomain.com
。但现在我有另一个使用 gh 页面的项目,名为 someotherproject
。 url 现在重定向到 mycustomdomain.com/someotherproject
而不是 someotherproject.github.io
。
这工作正常吗?
But now I have another project that uses gh pages called someotherproject. The url now redirects to mycustomdomain.com/someotherproject instead of someotherproject.github.io.
这是官方文档中描述的“Supported custom domains”
After you configure a custom domain for a user or organization site, the custom domain will replace the <user>.github.io
or <organization>.github.io
portion of the URL for any project sites owned by the account that do not have a custom domain configured.
For example, if the custom domain for your user site is www.octocat.com
, and you have a project site with no custom domain configured that is published from a repository called octo-project
, the GitHub Pages site for that repository will be available at www.octocat.com/octo-project
.
报告为 an issue in 2016:
I'm afraid this can't be disabled. If you have a CNAME file in a User pages site you other project pages will redirect to this Url.
You can override it by adding a different CNAME to your project page though or just create another Project site to act as your user page.
在 2020 年,Oliver Vorasai 提到了一个可能的解决方法:
The Problem
- Have portfolio repository at https://github.com/username/username.github.io
- https://github.com/username/username.github.io uses custom domain at
www.username.com
- Created another project at https://github.com/username/my-new-project
- Create
gh-pages
branch so Github Pages will host it
my-new-project
should be accessible at https://username.github.io/my-new-project/
- https://username.github.io/my-new-project/ it is automatically redirected to www.username.com/my-new-project and causes 404.
The Solution
- Rename the https://github.com/username/username.github.io repository to https://github.com/username/username-something
- https://github.com/username/my-new-project should now be available at https://username.github.io/my-new-project/
- www.username.com is still working, subsequent projects should get standard Github Pages urls without custom domains.
虽然不理想,如Emma Sax 所述:
I still think the best solution would be an option in the GH Pages settings of a project page to not redirect the domain of a project page.
This way, users would have a choice of having username.github.io/project-page
redirect to www.customdomain.com/project-page
or having it stay where it is.
It's frustrating to me that we even need to find an alternative solution at all.
我认为有几个问题与 github 页有关。
首先,当尝试通过将 repo 命名为与我的用户名相同来创建我的用户页面时,我希望 url 是这样的 myusername.github.io
。相反,它看起来像这样 myusername.github.io/myusername
.
我一直在通过命名我的存储库 myusername.github.io
来解决这个问题,它产生正确的 URL.
现在,我想用这个用户页面创建一个自定义域。我可以通过上述解决方法使用我的自定义域,但这现在会影响所有其他使用 github 页面的存储库。例如,我将 myusername.github.io
设置为使用 mycustomdomain.com
。但现在我有另一个使用 gh 页面的项目,名为 someotherproject
。 url 现在重定向到 mycustomdomain.com/someotherproject
而不是 someotherproject.github.io
。
这工作正常吗?
But now I have another project that uses gh pages called someotherproject. The url now redirects to mycustomdomain.com/someotherproject instead of someotherproject.github.io.
这是官方文档中描述的“Supported custom domains”
After you configure a custom domain for a user or organization site, the custom domain will replace the
<user>.github.io
or<organization>.github.io
portion of the URL for any project sites owned by the account that do not have a custom domain configured.For example, if the custom domain for your user site is
www.octocat.com
, and you have a project site with no custom domain configured that is published from a repository calledocto-project
, the GitHub Pages site for that repository will be available atwww.octocat.com/octo-project
.
报告为 an issue in 2016:
I'm afraid this can't be disabled. If you have a CNAME file in a User pages site you other project pages will redirect to this Url.
You can override it by adding a different CNAME to your project page though or just create another Project site to act as your user page.
在 2020 年,Oliver Vorasai 提到了一个可能的解决方法:
The Problem
- Have portfolio repository at https://github.com/username/username.github.io
- https://github.com/username/username.github.io uses custom domain at
www.username.com
- Created another project at https://github.com/username/my-new-project
- Create
gh-pages
branch so Github Pages will host itmy-new-project
should be accessible at https://username.github.io/my-new-project/- https://username.github.io/my-new-project/ it is automatically redirected to www.username.com/my-new-project and causes 404.
The Solution
- Rename the https://github.com/username/username.github.io repository to https://github.com/username/username-something
- https://github.com/username/my-new-project should now be available at https://username.github.io/my-new-project/
- www.username.com is still working, subsequent projects should get standard Github Pages urls without custom domains.
虽然不理想,如Emma Sax 所述:
I still think the best solution would be an option in the GH Pages settings of a project page to not redirect the domain of a project page.
This way, users would have a choice of having
username.github.io/project-page
redirect towww.customdomain.com/project-page
or having it stay where it is.It's frustrating to me that we even need to find an alternative solution at all.