Using "jekyll-redirect-from" with GitHub Pages
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
- Install the gem locally so you can make sure it works on your local Jekyll
gem install jekyll-redirect-from
- Enable the gem in your
_config.yml(not using a_plugin/like you might expect)
gems:
- jekyll-redirect-from
- 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
GitHub API rate limit exceeded. Comments available again at