Using "jekyll-redirect-from" with GitHub Pages

This post was published in 2014 and is kept here for reference. It may contain information that's outdated or inaccurate. All external links and references have been updated to point to archived versions on archive.org where possible.

Last week GitHub finally added support for some useful plugins to their implementation of Jekyll used for GitHub Pages.

The most notable of these is the support for the jekyll-redirect-from plugin.

When I first moved from Tumblr over to Jekyll back in 2012, I wrote about the pains of maintaining old URLs. Tumblr uses a permalink structure of /post/<post-id>/<slug>/, with the <post-id> being an arbitrary number that means nothing to us in Jekyll.

The solution I had arrived at back then was to generate the directory structure using the Jekyll Alias Generator plugin, and then to add the generated redirect pages to my repository.

Not a very nice solution, as it meant keeping the redirects in the code base as generated HTML files, but it was the only solution.

The jekyll-redirect-from plugin does essentially the same thing — outputting a HTML file in your _site/ directory for each redirect you specify, but at least now it’s supported by GitHub pages, so it will mean not cluttering up my codebase.

To use the plugin you have to do a couple of things

  1. Install the gem locally so you can make sure it works on your local Jekyll
gem install jekyll-redirect-from
  1. Enable the gem in your _config.yml (not using a _plugin/ like you might expect)
gems:
  - jekyll-redirect-from
  1. Add redirect_from: [list or single url] to your post frontmatter
redirect_from:
  - "/post/some-old-slug/"

And that’s it.

I’m still waiting for the day when Jekyll supports proper 301 redirecting, but this will do for now.

Read more about jekyll-redirect-from:

This post is also available in plain text

[Comments]

Want to comment? You can do so via Github.
Comments via Github are currently closed.

[Webmentions]

Want to reply? I've hooked up Webmentions, so give it a go!