How to disable section but child are accessible?


#1

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.


#2

both can help


#3

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/


#4
  • 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


#5

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


#6

only for index.md !


#7

@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>