【问题标题】:How to redirect in nanoc如何在 nanoc 中重定向
【发布时间】:2012-12-04 23:37:18
【问题描述】:

我是 nanoc 的新手,我只是通过博客设置的。

我所有的帖子都在/blog/post/Month/Post_name.html 下,但是每次我访问/post/ 时,它都会向我显示 Apache 文件列表视图。

我希望/blog/post/* 重定向到/blog/(其中包含所有博客文章的列表),但是当访问/blog/post/Month/Post_name.html 时,它应该显示正确。

那么,我该怎么做呢?

【问题讨论】:

    标签: apache nanoc


    【解决方案1】:

    这是一个关于 Apache 的问题,而不是 nanoc。

    在您的配置文件中,确保Options 不包含Indexes。这将关闭目录列表。

    对于重定向,您可以使用mod_alias。看看documentation for redirect

    【讨论】:

      【解决方案2】:

      Arjan van der Gaag 为此类重定向提供了一个非常好的解决方案。根据his nanoc-template wiki on that topic,您只需在config.yaml 中添加一些信息:

      redirects:
        -
          from: /foo
          to: /bar
        -
          from: /baz
          to: /qux
      

      然后配置您的htaccess 文件以包含这些设置:

      <% if @site.config[:redirects] %>
      # Set up URL redirects<% @site.config[:redirects].each do |h| %>
      Redirect 301 <%= h[:from] %> <%= h[:to] %>
      <% end %><% end %>
      

      (授予https://github.com/avdgaag/nanoc-template/blob/master/content/htaccess.txt

      结果将如下所示:

      Redirect 301 /foo /bar
      Redirect 301 /baz /quz
      

      在这种情况下,301(“永久移动”)将过于苛刻:您需要 303 重定向(“查看其他”)。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-03-13
        • 2016-07-21
        • 2021-10-23
        • 2018-03-22
        • 2012-06-19
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多