Question

I am new to nanoc and I just setup by blog.

All my posts are under /blog/post/Month/Post_name.html, but every time I visit /post/, it shows me the Apache file list view.

Rather I want /blog/post/* to redirect to /blog/ (which contains a list of all blog posts), but when accessed the /blog/post/Month/Post_name.html, it should show right.

So, how do I do it?

Was it helpful?

Solution

This is a question about Apache, not so much about nanoc.

In your configuration file, make sure that the Options does not include Indexes. This will turn off directory listings.

For redirection, you can use mod_alias. Take a look at the documentation for redirect.

OTHER TIPS

Arjan van der Gaag has a really nice solution for redirects like this. According to his nanoc-template wiki on that topic, you'll only need to add some info to your config.yaml:

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

Then configure your htaccess file to include these settings:

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

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

The result will look like this:

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

A 301 ("Moved Permanently") will be too harsh in this case, though: you'll want a 303 redirect ("See other").

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top