Stop the default of individual folder/index.html for each page?

I have my content organized like this:

  • Posts: content/posts
  • Pages: content/pages

Each page and post also has a slug in the front matter. I’ve also tried the following:

  posts = "/:slug/"

When I publish the site, however, the slugs work, but every post and page has a folder and index.html created for it.
This seems like…rather odd default behavior, especially when I read in the docs “Hugo assumes that the same structure that works to organize your source content is used to organize the rendered site.”

My goal: to generate my site with pages and posts located at the root (, or, using the slug I define. However, I can’t find a way to do that, and I don’t want to slowly accrete hundreds of subfolders for pages and posts.

Grateful for instructions or guidance.

1 Like

Set uglyURLs = true, Check the documentation here, Configuration

Thanks @pamubay, but that’s not quite what I mean. I’m referring to the directory structure of the generated site, not the URLs.

I’m trying to avoid a generated directory structure like this:

I’m trying to avoid having (eventually) hundreds of subfolder/index.html on the published site directory. I want my input to be content/posts and content/pages, but the output directory structure to be /awesomepost.html and /awesomepage.html (made into /awesomepost and /awesomepage via slugs). I’m genuinely surprised that the default behavior would be to created hundreds of subfolders in a published site.

It is standard behavior for web servers to read this structure in order to generate URL rewriting (the kind you want, in fact).

There is no performance issue, so if this is your preference you will need to figure out another way to get your web server to create URL rewrites. If you need to understand more about how URL rewrites work, please consult the docs for your web server. :slight_smile:

I’ve been building websites for 20 years, but I’m new to Hugo, haven’t seen this kind of scheme before, and the clues I found in the docs aren’t working for me. Yes, I could make everything be rewritten, but again–that’s not what my stated goal is. I want to avoid potentially hundreds of subfolders, and am looking for ways to do that from within Hugo (if possible).

Hugo is not involved in the URL rewriting. The web server is. So you can output those files as you want, but then you have to configure your webserver to know what to do. Is that making sense?

If not, can you show an example of a site that works the way you are explaining it, and share which web server it is, and how it’s configured?

If you are using Apache, take a look at mod_rewrite - Apache HTTP Server Version 2.4.

I’m talking about output directory structure, not URLs (see above), and Hugo generates the output directory structure. That’s there in my comment that you quoted. Is that making sense?

You can:

  1. uglyURLs: true and set url in front matter
  2. uglyURLs: true and put those files in /content rather than /content/posts

In #2 /content/ becomes /example.html, whereas /content/posts/ becomes /posts/example.html.

The reason setting your permalinks for that section to /:slug/ doesn’t work is because it’s dependent on “pretty” urls.

Tried #1 before–it doesn’t work. I still get a subfolder/index.html for every blog post and page. I verified the front matter and config.toml is formatted correctly. Also, docs say setting the url in front matter overrides the uglyurl setting. Also, I don’t want ‘uglyurls’ (.html in URL)–I want to set the slug to whatever I choose, and have ‘awesomepost.html’ appear in the output root (not subfolder/index.html).

#2 might work, but again–I don’t want to dump pages (e.g., ‘About’) and posts in the same contents folder to generate from.

Again, my goals:

  1. Use content/posts and content/pages
  2. Hugo-generated output has public/awesomepage.html, public/awesomepost.html
  3. I control the presentation to visitors to show as mysiteurl/awesomepage/ and mysiteurl/awesomepost/

That’s about it. I can do this in Jekyll and Pelican, but can’t seem to suss it out in Hugo yet.

So, your end goal is basically how Hugo works out of the box. The only reaso you dislike it is that it creates … folders?


@bep Yes, the main thing I’m looking to control is the output folder structure. I’ve tried various combinations of permalink, url, uglyurls, slug settings to accomplish it, but no success.

Over time, it seems to me this would accumulate hundreds (or perhaps thousands) of subfolders in the file structure of the site. Rewrites, slugs, etc. are clear to me, but I was hoping to avoid the cluttered dir structure in the site source on the server.

A directory is a file. I’m not sure why it bothers you to have lots of folders created. It should be possible to create /mypost.html files in Hugo, but if you want the links to point to /mypost you would need to do some magic replacements yourself, and personally I would rather live with some extra folders.

Thanks for the suggestion, @bep. I’m brand new to Hugo and was just exploring this option, wondering if I could accomplish it; I didn’t realize it would create these kinds of responses. Sorry for any disruption.