Jekyll重定向链接

20

当你说它似乎没有完成工作时,你到底是什么意思?你到底尝试了什么?当你尝试时,到底发生了什么?你是使用GitHub Pages还是其他什么东西?在构建过程中或在加载页面时,你是否遇到任何错误? - Kevin Workman
该插件可以将一个URL重定向到一个页面,但不能重定向到另一个URL。 - Martin Delille
我正在使用 GitHub Pages。 - Martin Delille
我只是在这里发布我的答案:https://stackoverflow.com/questions/56067700/redirect-to-page-in-jekyll/56067716#56067716 - piecioshka
这个回答解决了你的问题吗?在Jekyll和GitHub Pages中重定向旧页面的最佳方法是什么? - Ciro Santilli OurBigBook.com
不,我的问题不是关于重定向内容的。我想通过一个简单的链接提供一个资产(在Dropbox上)。被接受的答案很好,完全符合Jekyll的思路。 - Martin Delille
2个回答

31

该插件可以实现重定向到外部URL。要重定向您的示例URL,请创建名为tmwtga.html的文件,并添加以下前置内容:

---
permalink: /tmwtga
redirect_to:
  - http://www.example.com
---

假设您的服务器支持无扩展名的URL(在这种情况下,GitHub Pages支持)。你可能不需要 permalink,但我添加了它,以防您在_config.yml中设置了默认值。

来源:https://github.com/jekyll/jekyll-redirect-from#redirect-to


谢谢你提醒我,我忘了那个! - Martin Delille

17

如果:

  • 您使用错误的HTTP响应代码(200 OK而不是301永久移动)是可以接受的,
  • 您托管在GitHub页面中,
  • 您想依赖内置功能,并且
  • 您不想使用GitHub工作流程进行构建和推送到gh-pages,那么

您可以按照以下步骤操作:

  1. 创建文件_layouts/redirect.html

 <html>
 <head>
     <meta charset="utf-8"/>
     <meta http-equiv="refresh" content="1;url={{ page.redirect }}"/>
     <link rel="canonical" href="{{ page.redirect }}"/>
     <script type="text/javascript">
             window.location.href = "{{ page.redirect }}"
     </script>
     <title>Page Redirection</title>
 </head>
 <body>
 If you are not redirected automatically, follow <a href='{{ page.redirect }}'>this link</a>.
 </body>
 </html>
  • 对于每个需要进行重定向的页面,使用以下内容:

  •  ---
     redirect:   https://www.example.org
     layout:     redirect
     ---
    

    这段 HTML 代码是对 W3C 教程提供的 HTML 代码的扩展,教程链接


    3
    值得注意的是,这本质上是重新实现插件。请在此处查看jekyll-redirect-from使用的模板:https://github.com/jekyll/jekyll-redirect-from/blob/master/lib/jekyll-redirect-from/redirect.html - Ross

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