Is there an existing feature to do this in a pretty way? Else can’t we have this feature as it looks better than the existing one?
It does not look better than the existing one that’s just your preference…
It’s not possible currently with Hugo features. Also, you want to “cover-up” your file structure. A slash at the end is basically what “god” (tim berner lee) intended to be. It means that the file you are loading is in the folder https://mydomain.com/apath/. without that slash, you would want the file apath in the root folder of your website. Is it there, or is It in /apath/index.html?
Long story short: you are on your own, if you want to create weird URLs. It’s probably possible with an .htaccess file that in the end shows an URL while loading a proper path.
People like to forget that an URL is a path to a file and only “index.ext” is the part that can be left out of a link. It’s in a folder. Which is “behind” a slash.
Hi, I get your point. But correct me if I’m wrong, isn’t that only applicable to baseURL/blog/ in this case? Considering post-name.md is a file inside /blog/, this should be baseURL/blog/post-name right?
That has to be possible. Normal people just don’t type in a url with a slash at the end. That’s confined to a small sliver of tech folk. Especially when you tell someone a URL.
It’s a static site, meaning it’s just normal HTML files in normal directories. The reason why it’s /post-name/ is because the browser automatically tries /post-name/index.html, which is what Hugo generates.
Hugo has no control over how browsers present directories and index.html files. If you want to do that, you would need to configure the web server, e.g. configure it to trim trailing slashes, and resolve URLs without trailing slashes to the corresponding directories.
Check the output of your hugo command. While the URL might be baseURL/blog/post-name internally, it’s in a folder public/blog/post-name/index.html - and that is why any browser adds a slash at the end. I am pretty sure that your URL if you finally get rid of that slash, will have no slash, but for the browser, it will still be a slashed URL in the end. Some providers like Netlify even add the slash automatically to your URL.
No, they do not. It is the server that sends a redirect request if the trailing slash is missing from an URL pointing to a directory, like described here for Apache:
You are right, well, I phrased it wrong, long day What I mean is that if inside a folder bla is an index.html then you will end up with a slash after bla - done by magic (yes, the server). But thanks for the correction better to be 100% right.