-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an option to trim trailing slashes from URLs #3934
Conversation
I forgot to mention that this is now ready to review. |
Any updates on this? I'd love to see this feature in Hugo. |
I'd love to see this merged. I want to migrate my website from Pelican to Hugo, but I want to keep the URLs in tact. And those URLs currently don't have trailing slashes. |
I will have to think about this one. The change set was a little bit bigger than I imagined. It looks correct, but I'm not sure I'm willing to maintain such a feature. |
With the risk of reopening the whole discussion I saw on Discourse: I understand why the way Hugo currently works is really convenient, because it requires no changes to your webserver. But the reasoning behind the trailing slash just isn't valid 100% of the time. This is my current setup in Pelican:
NGINX is configured in such a way that it will serve This is a valid usecase I'd think, right? |
This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help. |
It's a great feature request that worth waiting to be accepted or refused by human. |
Too sad this isn't merged. Actually, what Hugo calls "ugly urls" is called "pretty urls" on Netlify. Take a look at their docs:
It seems urls w/o trailing slashes are a standard in the modern web development. For God's sake, even this very PR url is without a trailing slash. |
The "prettiness" definition is slightly different, but not the opposite. Both Hugo and Netlify consider URLs ending in The only thing is that Hugo doesn't care about removing the trailing slash for non-Ugly URLs, while Netlify removes the trailing slashes too. FWIW I don't care much about the trailing slashes being present or not.. Why is that a big deal.. just URL aesthetics or a technical reason? |
Honestly, I find all these config options regarding url prettiness quite confusing. Maybe it's better to rename
It's a big deal when you are migrating a site which was already configured with "slashless" urls. Search engines treat |
This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help. |
Interesting that this issue is considered "stale", because the maintainers just chose to ignore it. Many compelling arguments have been put forth, but apparently that is not good enough... |
@DannyDev wrote:
Well, things are not what they appear on the surface. A few observations from an occasional helper:
|
See gohugoio#3934 . I did not rebase some of the added tests because their merge conflicts were more complicated; this is a proof of concept, and there are apparently licensing issues that need to be resolved.
As you can see from the GitHub notification, I tried rebasing this PR onto master. I didn't get to rebasing all the tests yet, but the feature seems to work overall if I manually test against my own static site and, if it would be enough to get this merged, I can try to rebase the tests or write equivalent ones in a few days. (Are there licensing issues? The original author has made a PR before #3933 and the CLA bot reports that they signed the CLA there; I also think I signed the CLA when submitting previous PRs, but the bot no longer seems to think that I have.) I still care a good deal about this feature and consider it essential for me to use Hugo, FWIW. (Incidentally, Hugo is orders of magnitude faster for me since the rebase — kudos to the maintainers' effort!) The diff so far is here: master...betaveros:trim-trailing-slash |
Any update on this please? Having URLs with a slash is a stopper for me to migrate a site to Hugo now |
@ngocketit Could you please elaborate why this is a blocker for you? |
@hanzei I intend to host the site on S3 with CloudFront and HTTPS. With the trailing slash, CloudFront fails to serve the site as it couldn't route, for example, |
CLA is signed 👍 |
Hey guys! Could you resolve conflicts and merge this PR? =) I'd really appreciate it |
Calling @bep to merge this |
See gohugoio#3934 . I did not rebase some of the added tests because their merge conflicts were more complicated; this is a proof of concept, and there are apparently licensing issues that need to be resolved.
Since it has not been merged, this is a quick fix. (only change the look, not really change the url) <!-- Put in <header> or anywhere -->
<script>window.history.replaceState("", "", window.location.href.replace(new RegExp("/(?!.*/)"), ""));</script> |
I personally use a custom regex-based script in order to remove the trailing slashes. Actually, I enable the ugly URLs option which appends It works quite well but it took me a while to make it work properly. It's kinda sad such a basic feature is not implemented in Hugo; a blog post should not end with a slash as it is not a directory... |
Hi! Just curious what the status is on this ? Simply cannot believe that this is not an option. Hope this will be implemented soon... |
It is absolutely ridiculous that this is not yet an option. As rosell pointed out 2+ years ago, plenty of CMS'es offer this. https://discourse.gohugo.io/t/hugo-support-for-urls-without-a-trailing-slash/6763/3 @jamieconnolly , I am happy to assist with any merge conflicts if you'd like to add me to the repo :) |
@bep Anyway we can get a status update on this? This is very much needed! |
I'm closing this for now. This is too big of a change for me to review/merge/maintain (I don't need this myself). We may revisit this later if/when we get more long term maintainers. This is open source: Time is limited. |
In that case, I guess I will be moving on from Hugo. |
when hosting on Cloudfront + S3, it doesn't use |
@dcu yes, point CF at your S3 static website URL and not directly at the bucket. https://www.reddit.com/r/aws/comments/68on7h/indexhtml_in_subfolders_via_cloudfront/ |
See gohugoio#3934 . I did not rebase some of the added tests because their merge conflicts were more complicated; this is a proof of concept, and there are apparently licensing issues that need to be resolved.
Sad to hear but understandable. FWIW I will probably be "maintaining" this feature by rebasing it onto my fork for as long as it's not too hard (no conflicts since when I last did this 8 months ago), with the caveat that there are basically no code tests left (doesn't seem worth it if it won't be merged; my standard for it working is "nothing breaks when I click around my blog"). |
Just to clarify -- it does seem like 95% of the work is already done. @bep if the PR is updated with new tests would you consider merging this? (would you prefer a new PR?) It just basically allows an option as a flag. The code changes are not that extensive ... pretty straightforward and could easily be managed moving forward from maintainers plus the community. |
Just wanted to let you know that I'm also interested in this functionality, but I don't have the knowledge to take over and improve this PR 😞 . |
Hugo adds trailing slashes by default and I didn't find a way to remove it in some other way. There is [permalinks] setting in config, which I changed to `posts = "/html/:slug.html"`, but there is still a traling slash. There is also an unmerged PR: gohugoio/hugo#3934 Sidenote: maintainer said he won't merge it because he doesn't need this feature and doesn't want to spend time on review / merge / maintainance.
+1 here |
So I tried adding support for this in GitLab pages a long time ago but I did not have time to work in it further, see: https://gitlab.com/gitlab-org/gitlab-pages/-/merge_requests/259 my plan was to start working on this after the former MR was merged. I might look into this in the future but my hands are tied these days. Still want this functionality though. |
See gohugoio#3934 . I did not rebase some of the added tests because their merge conflicts were more complicated; this is a proof of concept, and there are apparently licensing issues that need to be resolved.
+1, if Jekyll does it, GitHub Pages does it, and Netlify does it, why not Hugo? Such a shame that this PR get closed. At least GitHub Pages won't do the trailing slash after publishing, that is. (maybe, please don't @ me) |
@Hans5958 curious on how you said GitHub pages won't do the trailing slash? Just hosted there now and I have them.. curious on what you did? |
@joaopgrassi That is just a theory. I didn't test it so don't take my word from it. |
@Hans5958 ah ok.. well I can tell you that it does have the trailing slash on my blog hosted on gh-pages. So there's that :) |
Great. I was trying to move everything from Jekyll to Hugo and noticed there's this trailing slash I can't get rid of. Now the hell is let loose and it just added extra work for me to update all url. The reason I picked Hugo in the first place was so that my life would get easier, not harder... |
It lives behind a
trimTrailingSlash
option inconfig.toml
. There is no CLI flag for this option.It works by hooking into the
uglyURLs
functionality and then stripping out the.html
suffix when generating URLs. This means it generates/filename.html
files rather than/filename/index.html
. It also handles when there's no trailing slash in the page's URL when set through the front matter.It's all been tested, but if there are any I've missed please let me know.
I've documented the option in my fork of hugoDocs. I'll create a PR if/when this progresses.
See #3556 and https://discuss.gohugo.io/t/links-without-a-trailing-slash/831.