You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何实现GitHub个人空间路径无tree/main/访问指定repo内容?

解决GitHub Pages路径跳转问题的方案

方案1:Jekyll内置重定向(最省心)

  1. 编辑你username/username仓库根目录的_config.yml,添加:
redirect_from:
  - /repo
  1. 在根目录新建repo.md文件,内容:
---
redirect_to: https://github.com/username/repo
---

提交后等GitHub Pages重新构建,访问https://github.com/username/username/repo会直接跳转到正确仓库,路径不会带tree/main/。

方案2:自定义404页面兜底

如果Jekyll重定向没生效,用404页面做跳转:
在仓库根目录创建404.html,写入:

<script>
if (window.location.pathname === '/repo') {
  window.location.replace('https://github.com/username/repo');
}
</script>

当访问/repo触发404时,JS会自动跳转到目标地址。

方案3:分支绑定GitHub Pages

  1. 在username/username仓库新建一个名为repo的分支
  2. 在该分支根目录创建index.html,内容:
<meta http-equiv="refresh" content="0; url=https://github.com/username/repo">
  1. 进入仓库「Settings」→「Pages」,把源分支改成repo并保存。
    这样访问指定路径时,会加载这个分支的页面并自动跳转。

注意:所有修改提交后,GitHub Pages可能需要1-5分钟完成部署,耐心等一下再测试。

内容的提问来源于stack exchange,提问作者kwalker

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 04:15:08