从 Github gh-pages 永久重定向
我想创建一个主页,目前我认为 Github 的页面功能可以满足我的需求。但是,稍后我可能想切换到更成熟的 CMS/博客引擎。
如果我决定将主页移到其他地方,同时保留所有旧的 URI,是否可以从 Github 页面提供永久重定向(HTTP 301)?
I want to create a homepage and, for now, I think Github's pages features will serve my needs. However, I might want to switch to a more full-blown CMS/blog engine later on.
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我能推断出的最好结果是 Github 还没有添加这个。请参阅 Tekkub 2010 年 4 月的回复 :将其添加到功能请求列表中。另一条消息一月份来自另一位用户建议使用 META 标签作为解决方法(可能不是一个好的解决方案)。
Best I can deduce is that Github has not yet added this. See Tekkub response from April 2010 re: adding it to the feature request list. Another message from another user in January suggests a META tag as a workaround (probably not a good solution).
是的。很快,通过 在 GitHub Pages 设置中设置自定义域。
当您希望通过自定义域提供 GitHub 页面时,通常会出现这种情况(假设用户尝试访问 https ://kamarada.github.io/,然后浏览器重定向到 https://linuxkamarada.com/,但这些页面确实在 GitHub 上)。
但它也适用于您之前将网站由 GitHub Pages 提供服务并移至另一台服务器(例如 GitLab Pages)的情况(我想这也适用于 WordPress)。
请参阅此答案:用户尝试访问https://kamarada.github.io/,然后浏览器重定向到 https:// /linuxkamarada.com/,但这些页面实际上位于 GitLab 上。
Yes, it is. Shortly, set up CNAME redirection by setting a custom domain on your GitHub Pages settings.
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).
But it also works in the case when you previously had your website served by GitHub Pages and moved to another server, e.g. GitLab Pages (I imagine that could work for e.g. WordPress as well).
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://stackoverflow.com/a/36846720/ 895245 实际的 301 似乎不可能。
如果您想批量重定向:
至:
请执行以下操作。
离开之前
_layouts/default.html
:默认布局_config
使用默认布局:<前><代码>默认值:
-
范围:
小路: ''
价值观:
布局:“默认”
离开后
使用以下内容创建
_layouts/redirect.html
HTML 重定向源自 从 HTML 页面重定向:_config
包含:<前><代码>默认值:
-
范围:
小路: ''
价值观:
布局:“重定向”
新域:'http://new-domain.com/some/path
用指向
redirect
布局的符号链接替换每个非默认布局。这是该技术唯一丑陋的部分。我没有看到漂亮的非插件解决方案。Mass redirect layout technique
Individual page redirects are covered at: https://stackoverflow.com/a/36846720/895245 Actual 301s seem impossible.
If you want to mass redirect:
to:
do as follows.
Before you move away
_layouts/default.html
: the default layout_config
uses the default layout:After you move away
create
_layouts/redirect.html
with an HTML redirect derived from Redirect from an HTML page along:_config
contains: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.为了用户的安全,GitHub Pages 不支持客户服务器配置文件,例如 .htaccess 或 .conf。但是,使用 Jekyll Redirect From 插件,您可以自动将访问者重定向到更新后的 URL。
更多信息可以在这里找到:https://help.github.com/articles /redirects-on-github-pages/
For the security of their users, GitHub Pages does not support customer server configuration files such as .htaccess or .conf. However, using the Jekyll Redirect From plugin, you can automatically redirect visitors to the updated URL.
More info can be found here: https://help.github.com/articles/redirects-on-github-pages/