Configure post url for hugo website

#hugo

19 February 2025 | Updated on 27 February 2025

Configure post url permalink settings for hugo website and get warnings in case you create pages with duplicate slugs that would result in url collisions.

Configure permalinks for page types

  • change permalinks settings in your hugo.yaml configuration
    permalinks:
      # post: "/:year/:month/:slug/"
      post: "/:slug/"

Problem: Identical post URLs

  • hugo will lets you create multiple pages with the same slug/url warning
  • in case you changed permalinks behaviour to ignore subfolder structures like year and month collisions could happen more often

Get warnings for duplicate paths

  • be sure to include drafts via -D
hugo --printPathWarnings -D
  • of course you can also include this flag into your dev server command
    hugo server --buildDrafts --disableFastRender --cleanDestinationDir --printPathWarnings

Custom post url via slug

  • use the front matter of your post/page to configure the slug manually.
  • to create a useful slug by default you can adjust page archetypes

Example archetype configuration

  • you could change the archetypes/default to the following content:
    ---
    draft: true
    date: '{{ .Date }}'
    # lastmod: '{{ .Date }}'
    # tags:
    # - tag1
    # - tag2
    title: '{{ replace .File.ContentBaseName "-" " " | title }}'
    slug: '{{ replace .File.ContentBaseName " " "-" | strings.ToLower }}'
    # description: 'writeyourdescriptionhere'
    ---
  • and use a permalinks configuration with /:slug/ only (as seen at the beginning)
  • then use the following command to create a new post:
    hugo new content posts/2025/02/my-new-blog-post/index.md
    • the post is structured by subfolders in your git repo (year, month)
    • but hugo will generate a website without year or month in the url

Additional resources


Related content