从Github gh-pages进行永久重定向

19

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

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


您可能希望在Github支持论坛上为此功能点赞。 - samplebias
2
我在 Github 上找不到这个功能请求。 - James Ward
你想要将you.github.io/some/path批量重定向到new_domain.com/some/path吗?还是只需要单个重定向?我建议我们将这个用于批量重定向,因为单个重定向已经在以下链接中有所涵盖:https://dev59.com/Smkw5IYBdhLWcg3wDWIk 和 https://dev59.com/m2ox5IYBdhLWcg3wVC1y?lq=1 - Ciro Santilli OurBigBook.com
4个回答

6

啊,是的,关闭了,因为现在它在“列表”上了——我以前在哪里见过这个? meta解决方案很丑陋,但如果它足够好地愚弄谷歌,我可能会尝试一下。 - Fred Foo
两个链接都失效了...有恢复的可能吗? - YakovL

1

大规模重定向布局技术

有关单个页面重定向的内容,请参见:https://dev59.com/m2ox5IYBdhLWcg3wVC1y#36846720 实际的301似乎是不可能的。

如果您想进行大规模重定向:

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

到:

http://new_domain.com/some/path

做如下操作。
在您离开前,请执行以下步骤。
  • _layouts/default.html: the default layout

  • _config uses the default layout:

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

离开后

  • create _layouts/redirect.html with an HTML redirect derived from Redirect from an HTML page along:

    {% 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 contains:

    defaults:
      -
        scope:
          path: ''
        values:
          layout: 'redirect'
    new_domain: 'http://new-domain.com/some/path
    
  • replace every non-default layout with a symlink to the redirect layout. This is the only ugly part of this technique. I don't see a beautiful non-plugin solution.


1
为了保护用户的安全,GitHub Pages不支持客户端服务器配置文件,例如.htaccess或.conf。但是,使用Jekyll Redirect From插件,您可以自动将访问者重定向到更新的URL。
更多信息可以在这里找到:https://help.github.com/articles/redirects-on-github-pages/

1

是的,可以。简而言之,通过在GitHub Pages设置中设置自定义域名来设置CNAME重定向。

通常情况下,当您希望通过自定义域名提供GitHub Pages服务时(比如说用户尝试访问https://kamarada.github.io/,然后浏览器重定向到https://linuxkamarada.com/,但实际上页面仍托管在GitHub上),就需要这样做。

但是,在您先前使用GitHub Pages提供网站服务并转移到其他服务器(例如GitLab Pages)时,也可以使用此方法(我想这对于WordPress等网站也适用)。

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接