Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFE: Support for redirections #506

Open
OndraZizka opened this issue Jul 30, 2018 · 6 comments
Open

RFE: Support for redirections #506

OndraZizka opened this issue Jul 30, 2018 · 6 comments

Comments

@OndraZizka
Copy link
Contributor

OndraZizka commented Jul 30, 2018

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
Copy link
Contributor Author

OndraZizka commented Jul 30, 2018

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>

@ancho
Copy link
Member

ancho commented Aug 2, 2018

Interesting and very useful idea.

@jonbullock
Copy link
Member

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.

@bmarwell
Copy link

bmarwell commented Oct 8, 2021

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

@wessven
Copy link

wessven commented Nov 22, 2021

+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

@bmarwell
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants