Resolving Squarespace → Jekyll permalink incompatibility

January 21, 2015

One of the last things on my mind when going about the Jekyll transition was preserving my previous URL structure. For years, I have consciously made an effort to both “future-proof” and “prettify” my site’s URLs.

Squarespace threw a wrench in the works. When I was live on SS6, the URL to this blog post would probably look something like:

http://www.conormcclure.net/blog/2015/1/jekyll-url-structure/

For the most part, that structure was fine by me, especially because there was little I could do to change it. Squarespace added blog/ to the beginning of the URL (against my will) to indicate that it came from my blog (gasp), and the rest was organized by my to my liking: year, month, slug.

However, Jekyll would like to produce this instead:

http://conormcclure.net/2015/01/jekyll-url-structure/

This structure is actually preferable to me; no needless blog/ prefix, and the leading zeroes in the month slot add some pleasing geekiness and symmetry.

One can imagine my dismay when I realized, upon launching this site, that, despite my best efforts to smooth out every blog post’s slug, previously standing links to the blog threw 404 errors left and right. Why?! Yep, the pesky blog/ prefix, and the lack of leading zeroes. I had to fix this.

There was no way I was going to add blog/ back to my URLs just to preserve my old links—blasphemy. After playing with Amazon S3’s redirect features, I whipped up the following routine rule to effective redirect all requests starting with blog/ to the equivalent URL with out:

<RoutingRules>
    <RoutingRule>
        <Condition>
            <KeyPrefixEquals>blog/</KeyPrefixEquals>
        </Condition>
        <Redirect>
            <ReplaceKeyPrefixWith></ReplaceKeyPrefixWith>
            <HttpRedirectCode>302</HttpRedirectCode>
        </Redirect>
    </RoutingRule>
</RoutingRules>

To this day, I haven’t come up with a perfect fix for the (lack of) leading zeroes. Ideally, I’d like to handle this with a large variety of redirects, sending 2015/1/ to 2015/01/, and so on. However, I’ve yet to figure out how to do this with S3’s routing rules. Instead, my best solution is to simply rewrite my blog’s URL structure to leave out leading zeroes, foregoing prettiness for backwards compatibility.

I accomplished this by modifying the permalink settings in Jekyll’s _config.yml file to:

permalink: /:year/:i_month/:title/

The i_month forgoes the leading zeroes; everything else was left unchanged. Obviously, this is somewhat of a quick fix that leaves me unsatisfied, and I’m still searching for ways to preserve my old links while maintaining an ideal URL structure from here on out. If you’ve got an idea, feel free to email me.