Force disableKinds to return 404.html template and a 404 response status for section pages

Hi there,

Let’s say I want to have a website structure like this:

HOME

└───folder1
│ ├── file1.html
│ ├── file2.html

└───folder2
├── file1.html
├── file2.html

I need the child items from folder1 and folder2 to be accessible via url, but I want to get rid of the auto-generated section pages folder1 and folder2. In my case, I want the links to /folder1/ and /folder2/ to return a 404.html page with an appropriate status code.

In the docs, I found that the “disableKinds” attribute disables the generation of the list pages. Everything works well, except that the links to /folder1/ and /folder2/ still return a 200 status code and an empty HTML document. How do I force those list pages to show my styled 404.html page and return a 404 status code?

create 2 files
folder1/_index.md and forlder2/_index.md

Design it like 404 pages …

standard template should be a list.html

with custom templates - create layouts/folder1/list.html and layouts/folder2.html as template,
can be a complete 404 design without using the markdown files

HTH

Hey ju52, thanks for your input! I can see this solution as a workaround, because:

a) It forces you to use code duplication (multiple 404 templates containing the same code)
b) It will still return a 200 status code

Maybe there is a more elegant solution to this?

This is a task for your web server, IMHO you can not do this with hugo

1 Like

With disableKinds = ['section'] in your site configuration, section pages are not generated when you run hugo. Look at the contents of the public/ directory.

I suspect you are trying to test this with hugo server, which generates these empty pages as described here:
https://github.com/gohugoio/hugo/issues/6027 (closed by stalebot)

I tried to test it using the --disableKinds flag, but that seems to be the case, thank you!!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.