OT: Pretty URLS for non-html (e.g., PDF) files?

From the docs (https://gohugo.io/content-management/urls/), we can see that Hugo uses ‘pretty’ as opposed to ‘ugly’ URLS by default. So for instance https://remi-theriault.netlify.app/blog_violin works without adding .html at the end although its a static html file, which is great. But how can I turn this on for other file types too?

E.g., remi-theriault.netlify.app/cv won’t work without specifying .pdf (both the html and pdf are static files at the root of /static).

Right now I am using a Netlify redirect for each individual file but for many files, this can be a long process (and more maintenance). I wonder if there’s not an easier way to hide the file extension for all files and not just html? For example, in WordPress, I simply had to add “Options +MultiViews” at the top of my .htacces file. Thank you.

Edit: Redirected here from Wowchemy support.

1 Like

I see netlify there. You must add a content type to each URL that is NOT HTML or the server will assume HTML.

For PDF you need a header “Content-Type: application/pdf”.

Other than that: “Ugly/Pretty URLs” is a concept that has to do with the delivery of “websites” meaning ALWAYS HTML content. Everything else it “other” content. So there is no button-switch way to achieve that. If you want to output a PDF without having it in path/to/filename.pdf you will have to save it without file ending and force the content type for the browser.

1 Like

Using redirects is the way. If said files live in a specific directory, you could create a wildcard redirect. Haven’t tested it, but something like:

/files/*  /files/:splat.pdf

From a usability point of view, I believe it’s friendlier towards the end-users to keep the “.pdf” extention in the URL. Most desktop browsers nowadays have built-in viewers, but that’s not always the case, and many will be forced to download a file where they expect to visit a page.

1 Like

I think it is a very bad practice in terms of user experience to remove file extensions (other than .html) from URLs. To be honest I have never seen this on any website before. I hope I never will.

1 Like

This topic is really not about Hugo.

Hugo as noted above offers the tools to hide the .html extension.

Hiding other file extensions can be done with redirects but it is not good practice.

1 Like