jbake icon indicating copy to clipboard operation
jbake copied to clipboard

RFE: Support for redirections

Open OndraZizka opened this issue 6 years ago • 6 comments

Sometimes, the content structure has to be changed. In such case, the old URLs should still work. This is quite a challenge with a static website.

User could keep the old file with a link to the new location. He could add a metadata to the header and render a redirect <meta> element in the template.

However, it would be very nice if JBake could handle this and relieve the user from the burden:

  • The user could get a listing of the files he is about to move and store them in a single file.
  • This file would reside in the old "source directory".
  • It would also contain metadata header, with at least the new location.
  • The content source files could be deleted.
  • JBake would check this file and for each path, it would generate a simple page, using a special template, that would redirect the user to the right URL. The template would the metadata to create the new URL.

Let's say we're moving pages from content/beer to content/drinking/beer (because we also started drinking wine and rums :) ).
content/beer/jbake.redirect would contain:

newLocation=../drinking/beer/
~~~~~~~~~~~
reviews/budweiser-budvar.md
reviews/starobrno.md
...

JBake would generate pages with <meta> redirects:

content/beer/reviews/budweiser-budvar.html
content/beer/reviews/starobrno.html

With the redirects going to ${newLocation}${oldPath}

This is an idea I have now after reorganizing my site while it's still new. However, doing that to an existing site can sink it down in search engines for quite a long time, break potential dead links around the web etc. So it's quite an important role of the static site generator.

Sounds good?

Edit: Looks like Jekyll has something similar, although doesn't seem like it relieves much work.

OndraZizka avatar Jul 30 '18 04:07 OndraZizka

The page could be

<!DOCTYPE html>
<html>
  <head>
    <meta charset=utf-8>
    <title>Redirecting from ${oldPath}...</title>
    <link rel=canonical href="${...}">
    <meta http-equiv=refresh content="1; url=http://${site.host}${newLocation}${oldPath}">
  </head>
  <body>
    <h1>Redirecting...</h1>
    <a href="${site.host}">Click here if you are not redirected.</a>
    <script> document.location = "${...}";</script>
  </body>
</html>

OndraZizka avatar Jul 30 '18 04:07 OndraZizka

Interesting and very useful idea.

ancho avatar Aug 02 '18 18:08 ancho

I like the idea.

Seeing the Jekyll link... could we achieve this by defining the old-url in the metadata header of the newly "moved" file. That way JBake would know how to create the old url file which is is built using a redirect template file. Keeps it simple and ties the old url and new url together.

jonbullock avatar Aug 07 '18 11:08 jonbullock

Hey, I would also be interested in this. Will use a redirect template until then.

bmarwell avatar Oct 08 '21 11:10 bmarwell

+1 for me as well.

Redirections can, of course, be set up on the web server, but I do think that redirections is a useful feature for a static site generator.

I primarily author my documents in Asciidoc. I always think to myself, would I be able to take my document as-is, and use it for something else (e.g. generating an epub)? While I don't necessarily mind declaring extra attributes in my adocs, perhaps the individual documents is not the appropriate place for redirections to reside (which is how Jekyll does it). The structure of the website should not be determined by the individual post. A redirect file (as suggested by OP, and which is more in line with how to set up redirections on a web server or CMS) is perhaps more appropriate. Please keep in mind, though, that redirections need to be versatile. It's not necessarily sufficient to "lift-and-shift" the existing directory structure into a new directory. For example, it would be good to be able to support a redirection such as

/node/1234/ -> /content/beer/reviews/starobrno.html

wessven avatar Nov 22 '21 05:11 wessven

Also useful would be if we could create the .htaccess file using freemarker.

bmarwell avatar Jan 21 '22 12:01 bmarwell