【问题标题】:Jekyll redirect linkJekyll 重定向链接
【发布时间】:2017-02-01 02:31:00
【问题描述】:

我将我的网站 http://www.phonations.com 移至 Jekyll/GitHub 页面。

在此之前,我知道如何将我网站上的一些网址重定向到外部网址。现在该怎么做?

例如,我希望 http://www.phonations.com/tmwtga 重定向到 https://www.dropbox.com/s/tw1b0kvoc75c7lx/tmwtga.zip?dl=0 或其他一些 url(使用 git lfs)。

虽然插件"jekyll-redirect-from" 允许将路径重定向到页面,但它似乎不允许将路径重定向到另一种资源。

【问题讨论】:

标签: redirect jekyll github-pages


【解决方案1】:

该插件确实允许重定向到外部 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

【讨论】:

  • 谢谢我错过了!
【解决方案2】:

万一

  • 可以使用错误的 HTTP 响应代码(200 OK 而不是 301 Moved Permanently),
  • 您托管在 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>
    
  2. 对于您要重定向的每个页面,请使用以下内容:

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

HTML 代码是对tutorial by W3C 提供的 HTML 代码的扩展。

【讨论】:

猜你喜欢
  • 2013-04-03
  • 2011-08-24
  • 1970-01-01
  • 1970-01-01
  • 2020-08-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多