Making Hugo Generate Case Sensitive URLs

A few weeks ago I changed the permalink structure for my Indie post types, changing URLs such as /mf2/00276d65-8767-40fe-bb37-59fc075a4942/ to /mf2/2019/08/SMfBV/ to make them more citable, as well as make it nicer to read and i.e. see what year + month the content was from.

The last portion of the URLs I was randomly generating were short case-sensitive, alphanumeric strings which had no meaning other than being a unique URL. But on Monday I noticed that the URLs were not being treated with case sensitivity.

This was not ideal as it was meaning that I was effectively losing some of the randomness in URLs, and would increase the risk of conflicts in filenames.

I was going to amend my Micropub endpoint to generate lowercase slugs, but I've now found that it's a straightforward configuration change in Hugo to make this work natively in Hugo.

To make this change, we need to amend our config.toml and set the disablePathToLower flag to ensure that it will render the URLs for the built site in the case that they were generated:

# i.e. another top-level parameter, for reference, not required
title = "Jamie Tanna | Software (Quality) Engineer"

disablePathToLower = true

And that's it!

To make this work with my site I've also updated all URLs on existing /mf2/ content to redirect the lowercase URLs to the original ones, so any permalinks will remain valid.

NOTE: This unfortunately did not work well, as Netlify has decided to only serve files from lowercase paths, which is not very clear. I'll be having to treat all paths as lowercase, and redirect them from uppercase, so it will effectively mean I have lost the randomness afforded by using case-sensitive strings - not cool!

This was tested with Hugo version v0.58.3/extended.

Written by Jamie Tanna's profile image Jamie Tanna on , and last updated on .

Content for this article is shared under the terms of the Creative Commons Attribution Non Commercial Share Alike 4.0 International, and code is shared under the Apache License 2.0.

Tags

This post was filed under articles.

Related Posts

Other posts you may be interested in:

Interactions with this post

Interactions with this post

Below you can find the interactions that this page has had using WebMention.

Have you written a response to this post? Let me know the URL:

Do you not have a website set up with WebMention capabilities? You can use Comment Parade.