19

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

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

4

4 回答 4

6

我能推断出的最好的结果是 Github 还没有添加这个。请参阅2010 年 4 月的 Tekkub 回复:将其添加到功能请求列表中。1 月份另一位用户的另一条消息建议使用 META 标签作为解决方法(可能不是一个好的解决方案)。

于 2011-03-14T18:25:55.590 回答
1

大规模重定向布局技术

单个页面重定向在: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'
    

你搬走后

  • 使用从 HTML 页面_layouts/redirect.html重定向派生的 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布局。这是该技术唯一丑陋的部分。我没有看到漂亮的非插件解决方案。

于 2016-04-26T14:50:14.930 回答
1

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

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

于 2016-04-28T21:36:03.320 回答
1

是的。很快,通过在 GitHub Pages settings 上设置自定义域来设置 CNAME 重定向。

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

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

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

于 2021-03-12T14:58:37.367 回答