How to Redirect URLs in Jekyll Using Github Pages and the jekyll-redirect-from Plugin
02 Apr 2014When changing the permalink structure of your blog or migrating your blog from one blogging platform to another, you often want to change the permalink structure of your blog but keep the old URLs and have them redirect to the new pages. This will allow you to preserve your Google search rankings, tweet history, SEO, etc.
Fortunately, Github Pages makes this really easy because they recently enabled support for the jekyll-redirect-from plugin. To get these URLs to redirect, all you have to do is:
- Install jekyll-redirect-from. To do that, I ran the command
gem install jekyll-redirect-from --source http://rubygems.org
- Include this plugin in Jekyll by adding to your
_config.yml
:
gems:
- jekyll-redirect-from
- Add to the YAML metadata of the post a line describing the old URL which should be redirected. For example, if the original URL for this post was joshualande.com/2014/04/02/minimal-urls-jekyll, then we could redirect that URL to the new URL by adding a line to the YAML metadata of this blog post:
redirect_from: "/2014/04/02/minimal-urls-jekyll/"
jekyll-redirect-from is further documented here.
- Finally, if you use DISQUS to host comments on your blog, you will have to explicitly tell DISQUS that you changed the URLs for your blog posts. DISQUS provide an easy URL Mapper which is documented here.
If you have any questions or comments, please post them below. If you liked this post, you can share it with your followers or follow me on Twitter!