【问题标题】:Permanent redirect from Github gh-pages从 Github gh-pages 永久重定向
【发布时间】:2011-07-15 05:33:09
【问题描述】:

我想创建一个主页,目前我认为 Github 的页面功能可以满足我的需求。不过,我可能想稍后切换到更成熟的 CMS/博客引擎。

如果我决定在保留所有旧 URI 的同时将主页移动到其他地方,是否可以从 Github 页面提供永久重定向 (HTTP 301)?

【问题讨论】:

  • 您可能想在 Github 支持论坛上对该功能 +1。
  • 我在 github 上找不到这个功能请求。
  • 您想以you.github.io/some/path 的身份大规模重定向到new_domain.com/some/path 吗?还是只有个别重定向?我建议我们将其保留用于大规模重定向,因为单个重定向包含在:stackoverflow.com/questions/10178304/…stackoverflow.com/questions/9276817/…

标签: http redirect github jekyll github-pages


【解决方案1】:

我能推断的最好的结果是 Github 还没有添加这个。请参阅Tekkub response from April 2010 re:将其添加到功能请求列表中。另一条消息from another user in January 建议使用 META 标记作为解决方法(可能不是一个好的解决方案)。

【讨论】:

  • 啊,是的,已关闭,因为它现在“在名单上”——我以前在哪里见过那个? meta 的解决方法很丑陋,但如果它足以欺骗 Google,我可能会尝试一下。
  • 两个链接都坏了..有没有机会恢复这些?
【解决方案2】:

大规模重定向布局技术

单个页面重定向包含在:https://stackoverflow.com/a/36846720/895245 实际 301 似乎是不可能的。

如果你想批量重定向:

http://you.github.io/some/path

到:

http://new_domain.com/some/path

如下操作。

在你离开之前

  • _layouts/default.html:默认布局

  • _config 使用默认布局:

    defaults:
      -
        scope:
          path: ''
        values:
          layout: 'default'
    

离开后

  • 使用从Redirect from an HTML page 派生的 HTML 重定向创建 _layouts/redirect.html

    {% assign redir_to = site.new_domain | append: page.url %}
    <!DOCTYPE html>
    <html>
    <head>
      <meta charset="utf-8">
      <title>Redirecting...</title>
      <link rel="canonical" href="{{ redir_to }}"/>
      <meta http-equiv="refresh" content="0;url={{ redir_to }}" />
    </head>
    <body>
      <h1>Redirecting...</h1>
      <a href="{{ redir_to }}">Click here if you are not redirected.<a>
      <script>location='{{ redir_to }}'</script>
    </body>
    </html>
    
  • _config 包含:

    defaults:
      -
        scope:
          path: ''
        values:
          layout: 'redirect'
    new_domain: 'http://new-domain.com/some/path
    
  • 用指向redirect 布局的符号链接替换每个非默认布局。这是这项技术唯一丑陋的部分。我没有看到漂亮的非插件解决方案。

【讨论】:

    【解决方案3】:

    为了用户的安全,GitHub Pages 不支持客户服务器配置文件,例如 .htaccess 或 .conf。但是,使用 Jekyll Redirect From 插件,您可以自动将访问者重定向到更新后的 URL。

    更多信息可以在这里找到:https://help.github.com/articles/redirects-on-github-pages/

    【讨论】:

      【解决方案4】:

      是的,是的。很快,通过setting a custom domain on your GitHub Pages settings 设置CNAME 重定向。

      当您希望通过自定义域提供 GitHub 页面时,通常会出现这种情况(假设用户尝试访问 https://kamarada.github.io/,然后浏览器重定向到 https://linuxkamarada.com/,但页面确实在 GitHub 上) .

      但它也适用于您之前让 GitHub Pages 为您的网站提供服务并移动到另一台服务器的情况,例如GitLab 页面(我想这也适用于 WordPress)。

      this answer:用户尝试访问https://kamarada.github.io/,然后浏览器重定向到https://linuxkamarada.com/,但页面实际上在GitLab上。

      【讨论】:

        猜你喜欢
        • 2015-12-22
        • 2011-08-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-02-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多