Creating Different Pages with URLs like www.example/page/ and www.example/page.html in Hugo

Hello everyone,

I’m working on a Hugo project and I need to create two different pages with the following URLs:

  1. www.example/page/
  2. www.example/page.html

I want these pages to have distinct content and be generated simultaneously from my Hugo site. Does anyone know the best way to achieve this? Any detailed steps or configuration examples would be greatly appreciated.

Thanks in advance for your help!

I would say on the long run, I think you won’t be lucky with interfering with Hugos Content organization but you could do with frontmatter url: parameter.

try this and check the result:

with this content file for your target /page.html:

  • content/_page.md (note the leading underscore in filename)
    ---
    title: UGLY url
    url: /page.html
    ---
    

and these files for normal content files

  • content/index.md

    ---
    title: Mixed ugly and pretty urls
    ---
    
  • content/page/index.md

    ---
    title: PRETTY url
    ---
    

and this layout and config to get a running site

layouts/_default/baseof.html
<!doctype html>
<html lang="en-us">
   <head>
      <meta charset="utf-8" />
      <title>Hugo Forum - Topic-50794</title>
   </head>
   <body>
      <h2>{{ .Title }}</h2>
      {{ block "main" . }}{{ end }}
   </body>
</html>
layouts/_default/home.html
{{ define "main" }}
   <ul>
      {{ range site.RegularPages }}
         <li><a href="{{ .RelPermalink }}">{{ .Permalink }}</a></li>
      {{ end }}
   </ul>
{{- end -}}
layouts/_default/single.html
{{ define "main" }}
   {{ .Content }}
{{- end -}}
hugo.toml
# deploy to root
baseURL = "https://www.example.com/"
# could use "en-US" here aswell
languageCode = "en"
# Website title
title = "Hugo Forum - Topic-50815"