【问题标题】:Forbid user to explore Index of/ with Jekyll禁止用户使用 Jekyll 浏览索引
【发布时间】:2015-03-22 06:24:52
【问题描述】:

我有一个似乎根本没有记录的问题。当您从 Jekyll 博客键入自定义 url 时,您可以浏览站点目录:

http://example.com/category/article(显示文章) -> 如果有人输入了 Jekyll 中没有引用的http://example.com/category/,他可以找到这个:

我希望 Jekyll(或者我猜是 htaccess)只显示我实际发布的页面。也许返回一个自定义 404 页面来重新路由用户。这里的主要问题是谷歌的搜索引擎优化,它索引这种内容,它很丑:)

【问题讨论】:

    标签: url http-status-code-404 jekyll


    【解决方案1】:

    这是因为您的文件夹中没有 index.html 文件。

    杰基尔之道

    在 github 页面上,您将收到 404 错误,而不是目录列表。

    在另一种类型的主机上,您可以使用jekyll-redirect-from 并制作这样的 404.html 页面:

    ---
    layout: default
    title: 404 Not Foune
    permalink: /404.html
    redirect_from:
      - /category/
      - /other/folder/to/protect/
    ---
    
    <h2>This is a 404 !</h2>
    

    这将创建重定向到 404 页面的 /category/index.html 和 /other/folder/to/protect/index.html 文件。

    处理apache

    .htaccess

    Options -Indexes
    ErrorDocument 403 /path/from/root/404.html
    

    这很丑陋(为 403 禁止返回一个 404 页面)但它可以解决问题。

    【讨论】:

    • Jekyll 有没有办法检测到它,因为我的网站有很多不同的类别模式? (而且很难保护所有这些,尤其是当我在我的网址上使用两个嵌套类别时)。
    • 您在哪里托管?
    • OVH,我在 FTP 上“glynn”我的文件。
    猜你喜欢
    • 2015-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-20
    • 2011-10-09
    • 1970-01-01
    • 1970-01-01
    • 2013-01-13
    相关资源
    最近更新 更多