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:
Mentioned elsewhere on this site
- On migrating from Tumblr to Jekyll Bootstrap
See my new post about using jekyll-redirect-from with GitHub Pages for automatic handling of redirects.
Related posts
- Moving to GitHub Actions (and adding .txt posts)
This year I moved the blog from GitHub Pages’ built-in Jekyll to a GitHub Actions workflow, then added .txt URL support for posts. Inspired by Terence Eden’s blog post about text-only websites.
- Jekyll for dummies
2014 has been heralded as “the year of flat-file websites”. This blog in fact uses Jekyll to generate the very blog post you are reading. I’ve been using Jekyll in some form since early 2012 (here’s how I migrated from Tumblr), and for me it works perfectly as a means to publish content.
- Reducing commit log noise caused by a GitHub Action
I have a “now playing” widget on my /now page that shows the last track scrobbled to Last.fm. It’s powered by a GitHub Actions workflow that polls the Last.fm API every hour and commits the result to the repo. It worked fine, but quietly polluted my commit history.
Discussion
No interactions yet
Join the conversation
Reply from your own site with a Webmention (how?).
