【问题标题】:github project sub-directory redirects to custom domaingithub项目子目录重定向到自定义域
【发布时间】:2017-09-21 21:44:43
【问题描述】:

我在这里有一个 github 项目页面: lwymarie.github.io/QPQ_Web/Quasars_Probing_Quasars/Welcome.html

该项目名为 QPQ_Web。其中有一个 index.html 文件,它指向 Quasars_Probing_Quasars 子目录中的 Welcome.html 文件,所有其他 html 文件也存储在其中。

我想用 www.qpqsurvey.org 替换 URL 的整个 lwymarie.github.io/QPQ_Web/Quasars_Probing_Quasars/ 部分。即我想跳过 URL 中的 Quasars_Probing_Quasars 子目录。请参阅当前的 www.qpqsurvey.org 网站以了解我的意思。

是否可以为此目的设置永久链接而无需重组我的文件?谢谢。

【问题讨论】:

    标签: redirect github dns github-pages subdirectory


    【解决方案1】:

    好像和这个问题有关:Set subdirectory as website root on Github Pages

    (1) 按照以下说明将您的子目录设为 GitHub 根目录,然后 (2) 按照 GitHub 的自定义域说明将http://www.qpqsurvey.org 重定向到 gh-pages:https://help.github.com/articles/using-a-custom-domain-with-github-pages/

    复制@CodeWizard 的答案,而我的答案的前半部分又从https://gist.github.com/cobyism/4730490 引用:

    将子文件夹部署到 GitHub Pages

    有时您希望在 master 分支上有一个子目录作为存储库的 gh-pages 分支的根目录。这对于使用 Yeoman 开发的网站之类的东西很有用,或者如果您在 master 分支中包含 Jekyll 网站以及其余代码。

    为了这个例子,让我们假设包含您网站的子文件夹名为dist

    步骤 1

    从项目的 .gitignore 文件中删除 dist 目录(默认情况下 Yeoman 会忽略它)。

    第二步

    确保 git 知道您的子树(您网站所在的子文件夹)。

    git add dist && git commit -m "Initial dist subtree commit"
    

    第三步

    使用子树推送将其发送到 GitHub 上的gh-pages 分支。

    git subtree push --prefix dist origin gh-pages
    

    轰隆隆。如果您的文件夹不是 dist,那么您需要在上面的每个命令中更改它。


    如果您定期执行此操作,您还可以create a script 在您的路径中包含以下内容:

    #!/bin/sh
    if [ -z "$1" ]
    then
      echo "Which folder do you want to deploy to GitHub Pages?"
      exit 1
    fi
    git subtree push --prefix $1 origin gh-pages
    

    它可以让你输入如下命令:

    git gh-deploy path/to/your/site
    

    【讨论】:

    • 完美运行!
    • 很高兴为您提供帮助。如果可行,您可以通过勾选 upvote-downvote 按钮下的复选标记来接受我的回答。
    • 接受!为自己是新手道歉。
    • 但是,如果您希望将两个子域重定向到 GitPages 的两个子目录怎么办?您不能同时将两个子目录设为根目录。具体来说,如何让 sub1.example.com 重定向 username.guthub.io/project1/site1/index.html 和 sub2.example.com 重定向 username.github.io/project2/site2/index.html?跨度>
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-28
    • 2014-04-10
    • 1970-01-01
    • 2019-12-23
    相关资源
    最近更新 更多