简体   繁体   English

从 Github gh-pages 永久重定向

[英]Permanent redirect from Github gh-pages

I want to create a homepage and, for now, I think Github's pages features will serve my needs.我想创建一个主页,目前,我认为 Github 的页面功能将满足我的需求。 However, I might want to switch to a more full-blown CMS/blog engine later on.但是,稍后我可能想切换到更成熟的 CMS/博客引擎。

Is it possible to serve a permanent redirect (HTTP 301) from Github pages in case I decide to move my homepage someplace else while preserving all the old URIs?是否可以从 Github 页面提供永久重定向 (HTTP 301),以防我决定将主页移到其他地方同时保留所有旧 URI?

Best I can deduce is that Github has not yet added this.我能推断出的最好结果是 Github 还没有添加这个。 See Tekkub response from April 2010 re: adding it to the feature request list.请参阅2010 年 4 月的 Tekkub 回复:将其添加到功能请求列表中。 Another message from another user in January suggests a META tag as a workaround (probably not a good solution).一位用户在 1 月份的另一条消息建议使用 META 标签作为解决方法(可能不是一个好的解决方案)。

Mass redirect layout technique大规模重定向布局技术

Individual page redirects are covered at: https://stackoverflow.com/a/36846720/895245 Actual 301s seem impossible.单个页面重定向涵盖在: https ://stackoverflow.com/a/36846720/895245 实际 301 似乎是不可能的。

If you want to mass redirect:如果要批量重定向:

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

to:到:

http://new_domain.com/some/path

do as follows.做如下。

Before you move away在你搬走之前

  • _layouts/default.html : the default layout _layouts/default.html : 默认布局

  • _config uses the default layout: _config使用默认布局:

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

After you move away你搬走后

  • create _layouts/redirect.html with an HTML redirect derived from Redirect from an HTML page along:创建_layouts/redirect.html并使用从 HTML 页面的 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 contains: _config包含:

     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.用指向redirect布局的符号链接替换每个非默认布局。 This is the only ugly part of this technique.这是这项技术唯一丑陋的部分。 I don't see a beautiful non-plugin solution.我没有看到一个漂亮的非插件解决方案。

For the security of their users, GitHub Pages does not support customer server configuration files such as .htaccess or .conf.为了用户的安全,GitHub Pages 不支持 .htaccess 或 .conf 等客户服务器配置文件。 However, using the Jekyll Redirect From plugin, you can automatically redirect visitors to the updated URL.但是,使用 Jekyll Redirect From 插件,您可以自动将访问者重定向到更新后的 URL。

More info can be found here: https://help.github.com/articles/redirects-on-github-pages/更多信息可以在这里找到: https : //help.github.com/articles/redirects-on-github-pages/

Yes, it is.是的。 Shortly, set up CNAME redirection by setting a custom domain on your GitHub Pages settings .很快,通过在 GitHub Pages settings 上设置自定义域设置CNAME 重定向。

This is usually the case when you want your GitHub Pages to be served through a custom domain (let's say the user tries to access https://kamarada.github.io/ , then the browser redirects to https://linuxkamarada.com/ , but the pages are indeed on GitHub).当您希望通过自定义域提供 GitHub 页面时,通常就是这种情况(假设用户尝试访问https://kamarada.github.io/ ,然后浏览器重定向到https://linuxkamarada.com/ ,但页面确实在 GitHub 上)。

But it also works in the case when you previously had your website served by GitHub Pages and moved to another server, eg GitLab Pages (I imagine that could work for eg WordPress as well).但它也适用于您之前的网站由 GitHub Pages 提供服务并移动到另一台服务器的情况,例如 GitLab Pages(我想这也适用于例如 WordPress)。

See this answer : the user tries to access https://kamarada.github.io/ , then the browser redirects to https://linuxkamarada.com/ , but the pages are actually on GitLab.看到这个答案:用户尝试访问https://kamarada.github.io/ ,然后浏览器重定向到https://linuxkamarada.com/ ,但页面实际上在 GitLab 上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM