Fastest Way to Create 301 Redirects in Jekyll and CloudCannon

A few days ago, someone on Twitter brought this article to my attention. The long and the short of it is this: including a date structure in your post urls is slow SEO suicide; the older a post is, the worse it will do in Google’s search results.

Visibility Index for Techcrunch.com on Google. Source: Sistrix.com

I obviously want to make sure none of my clients lose out on any traffic on account of me (especially since, let’s face it, dated permalink structures are objectively ugly), so I set out to make the necessary changes: change the permalink structures, set up 301 redirects, and update all the Disqus thread links.

CloudCannon offers a simple way of redirecting lots of pages.

You still have to actually retrieve all the different links, of course. Now, you could locate each individual post and copy-paste its link address, but if the website you’re working on has a lot of posts, this could take hours.

Luckily, I have a better solution:

Preparation

First, create a Excel file on your computer. Next, create a new page in Jekyll called ‘links.html’ and fill it with this code:

---
layout: page
title: links
permalink: /links/
---
{% for post in site.posts %}

{{post.url}}
<br>
{% endfor %}

This will generate links—in the correct syntax—to all the posts on your site.

Step 1

Simply copy-paste the list into the Excel file you created before.

Step 2

Then, change the permalink structure in your _config.yml (I prefer /:title/, which is like the ‘pretty’ structure but without the dates) and re-visit the /links/ page, which will now display a list containing the new links.

Copy-paste those into the next column of your Excel file.

Step 3

Then, select all the populated cells in your Excel file and copy-paste them into the 301.txt file you created on CloudCannon.

You’ll notice a weird symbol highlighted in red following each link.

Select one of them, hit cmd-c, then cmd-f to bring up CloudCannon’s built-in search function.

Paste it, and click “All”. Then hit backspace once to get rid of them all.

Step 4

Save the file.

Congratulations, now you’re done! Pretty easy, right?


PS. If your website uses Disqus comment threads, you can simply use Disqus’s redirect crawler, which can be found with the rest of their migration tools. This is far easier than manually creating a URL map.


Good luck!