When uglyURLs=true
, pages aren’t generated as I would expect.
Source |
Expected |
Actual |
Same |
_index.md |
index.html |
index.html |
Yes |
faqs.md |
faqs.html |
faqs.html |
Yes |
faqs/_index.md |
faqs/index.html |
faqs.html |
No |
faqs/index/_index.md |
faqs/index/index.html |
faqs/index.html |
No |
* All files are under content/
.
I noticed the same thing. For your third row’s example, that one really threw me off.
There is a long running issue about this here: Hugo with uglyURLs = true generates /public/section.html instead of /public/section/index.html · Issue #4428 · gohugoio/hugo · GitHub
I wanted to use ugly URLs because it seems to be the only way to have “normal” URLs as long as you rewrite them with a web server, such as /faqs/
for a page that lists FAQ items but allow for /about
(no trailing slash) to load a single page.
If the browser requests /about
(where that is a directory), the server will send a redirect to /about/
which the browser than loads. By pointing to /about
, you just force a second round-trip. And gain nothing.
In this case /about
wouldn’t be a directory, it would be about.html
. If you did have a directory such as /blog/
then you’d link to /blog/
to avoid the redirect.
It’s extremely common to avoid using a trailing slash as your canonical URL for non-directories. It’s how almost every site on the internet displays its URLs.
I’m on the fence on aborting my ~500 post migration from Jekyll to Hugo from this aspect of Hugo. Using non-pretty URLs has a lot of footguns and things to workaround. I also don’t want my URLs to change by having trailing slashes added to non-directories by using pretty URLs with Hugo.
For example, if you have social sharing, Hugo’s Permalink will include the .html
in the URL in the tweet but you wouldn’t want that so you have to strip it out but only if ugly URLs are enabled. There’s a bunch of examples of this.