Github 具有多个存储库的单个自定义子域的页面(使用路径)
Github Pages with single custom subdomain for multiple repositories (using paths)
我有多个 Github 存储库。所有这些 gh-pages
都已启用,并且可以通过路径访问存储库,例如:
username.github.io/repository1
,
username.github.io/repository2
,
...
现在我正在尝试创建一个自定义子域 docs.foo.tld
并让我的所有存储库 gh-pages
都可以通过
访问
docs.foo.tld/repository1
docs.foo.tld/repository2
...
我创建了一个 CNAME
条目 docs.foo.tld
到 username.github.io
但是当我在 github 的 repository1
存储库设置中添加这个自定义域 (docs.foo.tld
) 时,gh-pages
可以通过 [=15= 直接访问],而不是通过 docs.foo.tld/repository1
当对所有存储库使用相同的自定义子域时,我如何在路径段 /repository1
、/repository2
中使用所有这些存储库。
Also to note, when I try to add this custom subdomain to repository2
, I get the exception as the CNAME
is already taken.
CNAME 和设置自定义域只能在 .github.io 存储库中完成。
其他存储库不应包含 CNAME
并且您不应在其他存储库中设置自定义域。这些设置继承自 .github.io 存储库,在其他存储库中设置它们会覆盖根站点。
只需从项目仓库中删除 CNAME
条记录,并从项目仓库的设置中删除自定义域。您可能需要将自定义域名添加回 .github.io 存储库,但之后您应该按照自己的意愿进行所有设置。
There are several methods possible, that all require another webserver
where you host at least a .htaccess file or you make the rewrite in
the Apache configuration. I will not talk about them because I suppose
you do not want to use another webserver.
另一个技巧是在 github 上有一个项目,即 hub-project,它包含一个文件夹和一个 index.hml 文件,用于每个您拥有并重定向到相应项目的项目
我假设您知道如何在 Githup 上转到设置>>页面并在那里输入您的自定义域。然后您可能已经创建了 CNAME。
docs.foo.tld 现在将重定向到 username.github。io/hub
然后在 username.github.io/hub/ 中创建子文件夹和文件,如下所示:
username.github.io/hub/project1/index.html
username.github.io/hub/project2/index.html
此文件将可访问为
docs.foo.tld/project1/index.html
docs.foo.tld/project2/index.html
方法 1. 在这个 index.html 文件中,您将放置一些代码,重定向到您希望显示为子文件夹的相应 github 项目。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<script>
setTimeout(function() {
document.forms.redirected.submit();
}, 1000);
</script>
<head>
<noscript>
<meta http-equiv="Refresh" content="0; url='https://username.github.io/project1/index.html'" />
</noscript>
</head>
<body>
<form action="https://username.github.io/project1/index.html" method="GET" name="redirected">
</form>
</body>
</html>
方法2.我没有测试过,但是我看到github上有一个项目通过插件实现了jekyll的重定向功能https://github.com/jekyll/jekyll-redirect-from。如果您已经在使用 jekyll,那可能会很有趣。
我遇到了完全相同的问题,但根帐户是一个组织,而不是用户站点(但这没有区别)。解决方案非常简单(我有很多试验和错误):
- 如果尚未完成,请通过创建名为
myorg.github.io
. 的 git 存储库来创建特殊的 Organisation/User“保护伞”站点 as per the doc
- 在该存储库的设置中,在“页面”选项卡下,选择您的自定义域
docs.mydomain.com
。见图:
- 这个 repo 的内容由你决定。我个人使用 VitePress 和一个部署在
gh-pages
分支的 root 的小脚本。该脚本包括在项目根目录创建一个 CNAME
文件,内容为“docs.mydomain.com”
- 通过添加指向
myorg.github.io.
的 CNAME
条目来配置您的 DNS 区域与您的 Internet 提供商(注意尾随点 - 您的 IP 可能会或可能不会自动为您添加)。
- Return 到 GitHub 伞式存储库的页面设置,并检查子域是否已验证(可能需要几分钟)。
伞状文档站点就这些,其内容包含指向 docs.mydomain.com/project1
、docs.mydomain.com/project2
等的链接
现在,这是诀窍:没有诀窍。在您所有的实际项目中,只需部署您的文档即可。您可以在 docs
子文件夹中或不在任一分支中执行此操作,即在 master
或 gh-pages
中,这似乎无关紧要。
如果有,url 的 docs/
部分将替换为 project1/
等。不需要 CNAME,也不需要另一个自定义子域。
这是我的一个项目的配置:
查看 GitHub 如何指示网站发布的 URL。
这是我的 GitHub organisation and its umbrella site
结果:
奖金。如果您偶然将项目配置为具有子子域(这是我在找到解决方案之前尝试过的)——例如 https://project1.docs.mydomain.com
,上述配置也将“起作用”。也就是说,导航到 https://docs.mydomain.com/project1
会将您重定向到 https://project1.docs.mydomain.com
互联网很神奇,不是吗?
我有多个 Github 存储库。所有这些 gh-pages
都已启用,并且可以通过路径访问存储库,例如:
username.github.io/repository1
,username.github.io/repository2
,...
现在我正在尝试创建一个自定义子域 docs.foo.tld
并让我的所有存储库 gh-pages
都可以通过
docs.foo.tld/repository1
docs.foo.tld/repository2
...
我创建了一个 CNAME
条目 docs.foo.tld
到 username.github.io
但是当我在 github 的 repository1
存储库设置中添加这个自定义域 (docs.foo.tld
) 时,gh-pages
可以通过 [=15= 直接访问],而不是通过 docs.foo.tld/repository1
当对所有存储库使用相同的自定义子域时,我如何在路径段 /repository1
、/repository2
中使用所有这些存储库。
Also to note, when I try to add this custom subdomain to
repository2
, I get the exception as theCNAME
is already taken.
CNAME 和设置自定义域只能在 .github.io 存储库中完成。
其他存储库不应包含 CNAME
并且您不应在其他存储库中设置自定义域。这些设置继承自 .github.io 存储库,在其他存储库中设置它们会覆盖根站点。
只需从项目仓库中删除 CNAME
条记录,并从项目仓库的设置中删除自定义域。您可能需要将自定义域名添加回 .github.io 存储库,但之后您应该按照自己的意愿进行所有设置。
There are several methods possible, that all require another webserver where you host at least a .htaccess file or you make the rewrite in the Apache configuration. I will not talk about them because I suppose you do not want to use another webserver.
另一个技巧是在 github 上有一个项目,即 hub-project,它包含一个文件夹和一个 index.hml 文件,用于每个您拥有并重定向到相应项目的项目
我假设您知道如何在 Githup 上转到设置>>页面并在那里输入您的自定义域。然后您可能已经创建了 CNAME。
docs.foo.tld 现在将重定向到 username.github。io/hub
然后在 username.github.io/hub/ 中创建子文件夹和文件,如下所示:
username.github.io/hub/project1/index.html
username.github.io/hub/project2/index.html
此文件将可访问为
docs.foo.tld/project1/index.html
docs.foo.tld/project2/index.html
方法 1. 在这个 index.html 文件中,您将放置一些代码,重定向到您希望显示为子文件夹的相应 github 项目。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<script>
setTimeout(function() {
document.forms.redirected.submit();
}, 1000);
</script>
<head>
<noscript>
<meta http-equiv="Refresh" content="0; url='https://username.github.io/project1/index.html'" />
</noscript>
</head>
<body>
<form action="https://username.github.io/project1/index.html" method="GET" name="redirected">
</form>
</body>
</html>
方法2.我没有测试过,但是我看到github上有一个项目通过插件实现了jekyll的重定向功能https://github.com/jekyll/jekyll-redirect-from。如果您已经在使用 jekyll,那可能会很有趣。
我遇到了完全相同的问题,但根帐户是一个组织,而不是用户站点(但这没有区别)。解决方案非常简单(我有很多试验和错误):
- 如果尚未完成,请通过创建名为
myorg.github.io
. 的 git 存储库来创建特殊的 Organisation/User“保护伞”站点 as per the doc
- 在该存储库的设置中,在“页面”选项卡下,选择您的自定义域
docs.mydomain.com
。见图:
- 这个 repo 的内容由你决定。我个人使用 VitePress 和一个部署在
gh-pages
分支的 root 的小脚本。该脚本包括在项目根目录创建一个CNAME
文件,内容为“docs.mydomain.com” - 通过添加指向
myorg.github.io.
的CNAME
条目来配置您的 DNS 区域与您的 Internet 提供商(注意尾随点 - 您的 IP 可能会或可能不会自动为您添加)。 - Return 到 GitHub 伞式存储库的页面设置,并检查子域是否已验证(可能需要几分钟)。
伞状文档站点就这些,其内容包含指向 docs.mydomain.com/project1
、docs.mydomain.com/project2
等的链接
现在,这是诀窍:没有诀窍。在您所有的实际项目中,只需部署您的文档即可。您可以在 docs
子文件夹中或不在任一分支中执行此操作,即在 master
或 gh-pages
中,这似乎无关紧要。
如果有,url 的 docs/
部分将替换为 project1/
等。不需要 CNAME,也不需要另一个自定义子域。
这是我的一个项目的配置:
查看 GitHub 如何指示网站发布的 URL。
这是我的 GitHub organisation and its umbrella site
结果:
奖金。如果您偶然将项目配置为具有子子域(这是我在找到解决方案之前尝试过的)——例如 https://project1.docs.mydomain.com
,上述配置也将“起作用”。也就是说,导航到 https://docs.mydomain.com/project1
会将您重定向到 https://project1.docs.mydomain.com
互联网很神奇,不是吗?