Joshua Lande    About    Archive    Feed

How to Set Short URLs in Jekyll with Github Pages

In this post, I will describe how to make the URLs for your blog posts (what Jekyll calls permalinks) short and minimal. For example, I wanted the URL for this post to be joshualande.com/short-urls-jekyll without any tags, dates, or other extra characters. This url is short, looks nice, and is easy to share. I also read some speculation that smaller URLs help with SEO.

The Jekyll documentation, discusses the ability to set permalink to none in the _config.yml file:

permalink: none

But this created URLs like joshualande.com/short-urls-jekyll.html and I didn’t want my URLs ending in “.html”.

Next, I tried setting the permalink value to “/:title” in _config.yml:

permalink: "/:title"

This appeared to work, but broke the static pages I had setup (like joshualande.com/about). I could move all the static pages to just be blog posts, but that would have broken my archive of blog posts which should not include static pages.

Finally, I realized that I could get my desired result without messing up static pages by explicitly setting the permalink key in the YAML metadata of each post. For this post, I set:

permalink: short-urls-jekyll

It is unfortunate that you have to explicitly set this at the top of each blog post. But this does work, giving me beautiful URLs like joshualande.com/short-urls-jekyll. Please comment below if you know of a simpler way to way to do this.

Finally, if you already have existing permalinks and want them to redirect to your new url, you can do this by following the instructions on this blog post.

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!

comments powered by Disqus