How to disable section but child are accessible?

Hi guys,
I have this structure:

/content/menu/
/content/menu/page1.md
/content/menu/page2.md
...

and I set permalinks in config:

[permalinks]
  menu = "/:filename"

What is the best way to set /menu list as not existing (404) but /page1/ and /page2/are accessible?

I know I can put page1.md and page2.md in the root of content/ folder, but is a way how can I do the same if pages are in menu folder?

If I create empty file /layout/menu/list.html it shows nothing for /menu/ but ideally I would like to get 404 error.

both can help

Thanks for links, I already read this pages, but I am still confused how to achieve this. I tried to add index.md and _index.md with headless=true or without. I still get list of pages for url http://localhost:1313/menu/

  • rename menu/list.html template to empty.html
  • put anything in the content to check the right template is used

change index.md

  • set layout=“empty”
  • set headless=true in frontmatter

use hugo --debug to get more information

if I set headless then all children are 404 not found…

only for index.md !

@Marek_Lichtner You could redirect the user to your 404 page. So in your layout/menu/list.html have something like this

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="refresh" content="0; url=/404/" />
  </head>
</html>

Hi guys!

I’ve just found a solution that works for me. This is the content of _index.md:

+++
url = "/"
+++

The advantage is that the url to this branch is not displayed in sitemap.xml(!).

However, I don’t know if this solution will work permanently because the same URL is used for multiple pages. A headless option for branches (_index.md) would be safer.

This question is related.

Extremley late answer, but can you or someone else further explain?

I added “URL: /” to my _index.md Frontmatter, but it changes nothing. Same with “headless: true”. I still get the 404 error for every subpage.

the above solution is 5 years old. Hugo not the same today.

Is there a better solution today? I only want to get rid of the first section “/posts” without affecting the lower-level sections or my folder structure. I tried

_build:
render: never
list: never

for my _index.md file in the Frontmatter, but every time I do this it breaks the other subsections with the 404 error.

@Paro

You have posted the same question in three places:

Please do not do that, and please do not bump old topics. See:
https://discourse.gohugo.io/t/requesting-help/9132

Let’s continue this dicussion in your original topic:
https://discourse.gohugo.io/t/45618