NiK*_*iKo 47 hosting redirect github jekyll github-pages
这是我的Github存储库:https://github.com/n1k0/casperjs
有一个gh-pages
分支来保存项目文档,基本上是项目网站:https://github.com/n1k0/casperjs/tree/gh-pages
该分支机构在http://n1k0.github.com/casperjs/ - hurray上设置文档站点.
与此同时,我已经通过该casperjs.org
域名获取此网站,因此我按照CNAME
文档中的建议放置了一个文件:https://github.com/n1k0/casperjs/blob/gh-pages/CNAME - in他们的例子,该操作应该从www.example.com和charlie.github.com创建重定向到example.com ...
虽然该网站现在指向http://casperjs.org/,但没有301重定向从http://n1k0.github.com/casperjs/(旧网站网址)到新域名.
知道如何设置这样的重定向,如果可能的话?这是一个错误吗?如果是,我应该在哪里开一个问题?
Per*_*rry 29
将这个话题从死里复活,提到GH现在支持redirect-from的redirect-to参数https://github.com/jekyll/jekyll-redirect-from#redirect-to
只需将其添加到_config.yml即可
gems:
- jekyll-redirect-from
Run Code Online (Sandbox Code Playgroud)
这是索引页面的顶部.
---
redirect_to: "http://example.com"
---
Run Code Online (Sandbox Code Playgroud)
Jon*_*Lee 19
其他答案讨论了使用元刷新或 javascript 进行重定向。但OP询问了301重定向。答案是:不。这不可能。您在 GitHub Pages 上的站点是静态的,因此您对服务器没有任何控制权。
pio*_*ouM 13
为避免重复内容,您可以在第一时间添加如下的元规范:
<link rel="canonical" href="http://casperjs.org">
Run Code Online (Sandbox Code Playgroud)
您可以在主机检测后使用Javascript重定向,如下所示:
if (window.location.href.indexOf('http://niko.github.com') === 0) {
window.location.href = 'http://casperjs.org{{ page.url }}';
}
Run Code Online (Sandbox Code Playgroud)
但我同意,这不是HTTP重定向.
手动排版方式
如果你不喜欢使用https://github.com/jekyll/jekyll-redirect-from,那么自己实现它很容易:
a.md
:
---
layout: 'redirect'
permalink: /a
redir_to: 'http://example.com'
sitemap: false
---
Run Code Online (Sandbox Code Playgroud)
_layouts/redirect.html
基于从 HTML 页面重定向:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Redirecting...</title>
{% comment %}
Don't use 'redirect_to' to avoid conflict
with the page redirection plugin: if that is defined
it takes over.
{% endcomment %}
<link rel="canonical" href="{{ page.redir_to }}"/>
<meta http-equiv="refresh" content="0;url={{ page.redir_to }}" />
</head>
<body>
<h1>Redirecting...</h1>
<a href="{{ page.redir_to }}">Click here if you are not redirected.<a>
<script>location='{{ page.redir_to }}'</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
现在:
firefox localhost:4000/a
Run Code Online (Sandbox Code Playgroud)
将您重定向到example.com
.
像这个例子一样,redirect-from
插件不生成 301,只生成meta
+ JavaScript 重定向。
我们可以验证发生了什么:
curl localhost:4000/a
Run Code Online (Sandbox Code Playgroud)
在 GitHub 页面 v64 上测试,现场演示:https : //github.com/cirosantilli/cirosantilli.github.io/tree/d783cc70a2e5c4d4dfdb1a36d518d5125071e236/r
Github页面不支持.htaccess
或nginx/conf
https://help.github.com/articles/redirects-on-github-pages/
最简单的方法是:
HTML重定向:
index.html
<html>
<head>
<meta http-equiv="refresh" content="0; url=http://www.mywebsite.com/" />
</head>
<body>
<p><a href="http://www.mywebsite.com/">Redirect</a></p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
您为什么不使用http://www.w3.org/TR/WCAG20-TECHS/H76.html?
那会给
<meta http-equiv="refresh" content="0;URL='http://casperjs.org/'" />
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
14163 次 |
最近记录: |