Search code examples
netlifyhugo

Hugo: Escape special Characters in taxonomy (tag) paths


I have post tags like C# and F#. Similar cases also show up in titles.

The problem is that Hugo does not appear to support # in a url. Such pages 404 and fail my Netlify build. With content pages, I can set an explicit url to get around the special character.

The same can't be done for the auto-generated taxonomy pages. How can I get hugo to escape or strip special characters (like #) from urls?

Note: removePathAccents doesn't apply for non-accent special chars like # or %


Solution

  • You can set-up specific URL for almost anything in Hugo. To set-up a different URL for those tags:

    1. Create a file: ./content/tags/C#/_index.md
    2. Set the following in it's frontmatter (YAML assumed):
    url: "/tags/c-sharp"