Links without a trailing slash

Continuing the conversation from

I get the need to make things work out of the box. I’m curious why there is not an option to have pretty URLs without the trailing slash, like it was mentioned beforehand. It’s certainly not “erroneous.” If I have a file:

# /content/

we could just as easily generate a file like:

# /public/about.html

and that would make the link


make total sense, because it’s not a directory.

Jekyll currently lets you generate files both ways by setting the style of the permalink in the config.

Would love to keep the ball rolling on a config option for more flexibility here. I personally hate not having full control over my URLs. :slight_smile:

1 Like

I undestand the discussion, but your example (/about.html => /about) makes no sense to me. Wouldn’t you then need an extra routing mechanism?

Yep. But it’s how I would want the URLs to be generated and it’s trivial in any server configuration. That was just an example that shows the generation of files that wouldn’t use the directory method, ie:


Because, as people have already pointed out, having a URL without a trailing slash in this case is not semantic and downright confusing anyway.

I’m not arguing that no trailing slash should be the default behavior, I just want a flag to flip! And I don’t care if you name it --break-urls or whatever. I’ll gladly break them all up and down my site. :slight_smile:

Also, how was Hugo generating files in 0.11 to not have a trailing slash? If my example is just downright wrong, that’s okay. A flag to turn on 0.11 style generation would be awesome though.

OK, I understand.

I have been around for only since > 0.12 so I have no idea about that history, but Url regressions is one of Hugo’s biggest challenges.

1 Like

I think I may have found a case where the server actually needs trailing slashes to route correctly. My host serves static files through a nginx server (which I can’t configure directly) and my site is served over SSL. Any directory content (posts) renders fine as it automatically appends the trailing slash, but for pages created just within /content the default link doesn’t have a trailing slash.

In this case having a link like /about results in a nginx 400 error: “The plain HTTP request was sent to HTTPS port.” A non-ideal workaround so far has been to define menu items manually in the config. Is there a way to configure Hugo to also append trailing slashes to pages created in the main content directory? Adding a trailing slash to the base URL doesn’t seem to change the behavior.

Personally I also want no slash at the end.

I find it ironic that (see description of uglyurls option in config) links with a trailing slash (which convey you are going into a real directory", except we return an html file and break that convention) are considered “pretty” whereas a link to a file.html, of which you can clearly tell what will happen without even going there, is considered “ugly”. seems like a lot personal opinion is involved here, but anyway this is not my main point.

I know the common argument is “…but I don’t want to see the .html extension in the url because only the title of the content should matter” and my reply is:

  • why is a trailing slash any “prettier”, it saves a few characters but it’s much more ugly because it’s misleading about the content you will get
  • and my main point: why don’t we just store files on disk without html extension? that way we don’t need a trailing slash (because we don’t store content in a directory per post) and we don’t need a .html extension in the url (because the file has no .html extension) and the server will serve the right file and everything will just work fine with true pretty urls?

Your main point is moot once you start to store images etc. in the same folder as index.htm.

Besides, it’s a design choice taken by someone sometime. Hate it or love it. I like it.

1 Like

@bjornerik I don’t understand what you mean.
my main point was that you could store posts like so:
and so on. these are each files, so they can be served directly by the server with stock config, no trailing slash needed and no extension needed. there would also be no index.html and no images here (and even if there were, I think it would still work? why wouldn’t it?)

  • Where would you put the images that belongs to the hello-world post?
  • Where would you put alternative representations of the same content? (XML, JSON, whatever)?

Life gets soooo much easier by linking a single content to a directory on a file system, even if it adds a slash.

ah good point.

  • I put all my images together in an images directory. admittedly this is not very clean, keeping them closer to the post seems like a good idea, although I do sometimes use the same image in multiple posts.
  • I don’t have alternative content representations so that’s not an issue for me. But I can see how here having a directory with the default representation as index.html makes a lot of sense for this case. Just curious, is this a common thing? I assumed the vast majority of people just use html, what are the other representations used for?

Currently in Hugo it’s HTML for the single content, and HTML only.

But there are several GitHub issues in HIGH DEMAND that wants

  1. Group content and assets together (mostly images related to a post)
  2. Alternate output for the list pages (we have index.xml today, JSON may be a next step), and I guess we will also get there for single pages.

So, in the imaginary content/post/my-second-post folder you would have:

etc ...

Not all of the above, this would be configurable …

Having images in a separate folder (below static) is how it is today, and this works fine – but is not very elegant for images that is closely related to the content, and this also enables easier linking (relative to content folder) and exporting articles as a package etc.

Conclusion, I do not see your suggestion happen anytime soon.

1 Like

Anything new on this topic? I’d like to move some existing sites to Hugo, but keep the URLs precisely as they are now. I firmly believe in what Tim Berners-Lee stated 18 years ago as he said: Cool URIs don’t change. This means I can’t use a framework that’s not giving me full control of my URLs.

I fully understand the reasoning behind the decision to add a trailing slash in the default URL scheme. That makes a lot of sense. But I’d really like to get the behavior of v0.11 back as an option for the people that like to have control of their URLs. As Steve stated in the original thread: “it wouldn’t be hard to do”.

Steve is right, of course, and we would welcome and merge a solid pull request on this. But my motivation for doing this is myself isn’t sky high; I have other priorities – I’m a big fan of Tim Berners-Lee, though. Without him, none of this.

Is implementing support for non-trailing slash URLs on the roadmap, or this still something that is only likely to be implemented if somebody offers a pull request? I too would like to make use of Hugo for a lot of my sites, but without being able to tailor the URLs to match what I currently have, I have to hold off.

PRs are welcome. This is not on the roadmap.

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