Why Convert the URL/Path to Lowercase?

Why is the default behavior of Hugo to convert the url/path to lowercase? I was converting ~2,500 static pages to Hugo and didn’t realize this was the default behavior until I stumbled across lowercase URLs in my sitemap.xml. This is unintuitive.

As an SEO optimizer, I will say that the ability to use uppercase and lowercase letters in URLS opens a Pandora’s box of issues with indexing, duplication, and subsequent patching up, 301 redirects, and other unnecessary tasks and problems. It’s very good that they thought about us and made it so that we don’t have to worry about it :sweat_smile:

The trouble is this default behavior is not clearly documented, it is not intuitive, and it is not consistent.

For example, I migrated a page with the path /states/AZ.md. Hugo generated /states/AZ/index.html and Hugo server served /states/AZ/. However, /sitemap.xml linked to /states/az/. If I had pushed this code to Production (AWS S3), my sitemap would have contained 51 broken links.

1 Like

I am unable to reproduce this. Try it:

git clone --single-branch -b hugo-forum-topic-50736 https://github.com/jmooring/hugo-testing hugo-forum-topic-50736
cd hugo-forum-topic-50736
hugo server

Into the rabbit hole …

Thanks for the example, @jmooring.

I updated hugo.toml and reverted disablePathToLower to its default value (false).

I created a custom link to the page Arizona, which renders as <a href="/states/AZ">Arizona</a>. If I click the link, Hugo server serves http://localhost:1313/states/AZ/ (without redirect or error).

  1. Since Hugo server served /states/AZ/, I incorrectly assumed that Hugo generated the file /public/states/AZ.html. However, I only see /public/states/az.html in the file system.

  2. I’m on a Mac. I assumed URLs were case sensitive.

  3. On my project, I saw a separate issue that contributed to my confusion.

ERROR open /redacted/public/states/ak/index.htm: not a directory
ERROR open /redacted/public/states/ca/index.htm: not a directory
ERROR open /redacted/public/states/al/index.htm: not a directory
ERROR open /redacted/public/states/cn/index.htm: not a directory
ERROR render: failed to render pages: open /redacted/public/states/az/index.htm: not a directory

This leads me to … why does Hugo serve case-insensitive paths? My custom links would have failed when I went to Production.

I am not able to reproduce what you describe. I’ve updated the example to include case-sensitivity test links on the home page:

git clone --single-branch -b hugo-forum-topic-50736 https://github.com/jmooring/hugo-testing hugo-forum-topic-50736
cd hugo-forum-topic-50736
hugo server

Maybe you didn’t clear the public directory when you were changing file names or whatever.