How to enable URLs ending without a trailing slash on S3 and Cloudfront?

I’ve hosted my page on S3, and it ends with a trailing slash, for example, the URL is ‘example.com/post/post-1/’. How can I enable both URLs to work, ‘example.com/post/post-1’ and ‘example.com/post/post-1/’?
This is crucial for us as my company previously used ‘example.com/post/post-1’, and there are some cross-links now that don’t work.

Is there any way to resolve this?
Thank you.

This should not be an issue, any web server I know about will handle that.

See these two URLs, both work without issues. The server will redirect 1 → 2.

  1. https://zen-demo.xdeb.org/misc
  2. https://zen-demo.xdeb.org/misc/
1 Like

The same question was asked 25 days ago:

Nothing has changed since then, I think.

I still hope this feature will be implemented. :slightly_smiling_face:

hi all,
I re-drag the subject on top of the heap because it it a huge issue in SEO and mainly in https://search.google.com so Google Console for our web position.
Why ?
because you may find a lot of pages with the error in console (in French) “Autre page avec balise canonique correcte” . And no matter it is or not an error : the less errors you have, the better and quicker your site is indexed : simple.

For ex in my web site Hugo generated with the last version of Hugo (0.147.7): (I am hosted on Render, similar to CloudFront, but the issue is not the host)
Applications mobiles de gestion de stock et d'inventaire avec scan de code-barres pour professionnels
the Google console says : (screen copy of GG console)


the link of this page is sent from “Agence de développement d'applications mobiles code-barre, RFID et API” : this is exact,
but the canonical link defined in the sitemap is (I have verified, yes it is:)
Applications mobiles de gestion de stock et d'inventaire avec scan de code-barres pour professionnels” : the same but with a “/” at the end . The “/” comes from the build, not from the host.

The sitemap is generated in auto by Hugo : how can we (SEO) can choose simply (as in parameters) the fact the URL is built with or without a ‘/’ at the end ?

Thank you a lot for your attention to this issue.

yes another solution would be to program the host to send all the pages to the same page with “/” at the end … not standard, I will test in the meanwhile.
like (on Render) :
Capture d’écran_2025-06-22_16-22-28

The “huge issue” is that both of these requests return a 200 response:

https://www.productivix.com/fr/page/app-de-gestion-supply-chain-code-barre
https://www.productivix.com/fr/page/app-de-gestion-supply-chain-code-barre/

The first should return a 301 redirect, as it does by default on sites hosted by Amplify, Cloudflare Pages, Cloudflare Workers, Firebase, GitHub Pages, GitLab Pages, Netlify, etc.

Hi @jmooring , thanks for your remark, I submitted to solve @ Render support - because none of the rewrite or redirect rule does return a 301 code

yes , but please admit @jmooring , that it is incoherent to build list.html as default layout with :
<a href="{{ .Permalink }}" class="btn-main btn-main-sm">{{ i18n "read_more" }}</a>
where .Permalink is a link WITHOUT “/” at end and build sitemaps with link WITH “/” a end ??
If sitemap in Hugo does not have been produced, “/-at-the-end-links” would have never existed !

To take the bad at root-cause, waiting a “may-be-solution” in my host : please : How can I build sitemaps with “no-/-at-the-end-links” with Hugo ? (with multi-language)

The .Permalink and .RelPermalink methods return a value ending with a slash unless you enable uglyURLs or provide a url in front matter that includes an extension. This is true regardless of where you call the methods.

And “incoherent” is an unfortunate choice of words.

May be you are not pleased with my word, sorry but I am not pleased with the discovery of standard templates supplied with the default we discover some years after.

Can you please develop your answer because I an unable to understand it ? You say that if I modify a parameter somewhere, all the links build with Hugo will be “/-at-the-end-links” ?

Can we come back to the issue : as I cannot see :slight_smile: - it is impossible to have a std sitemap with “no-/-at-the-end-links” with Hugo?

You cannot somehow configure to Hugo to remove the trailing slash when calling the .Permalink or .RelPermalink methods, and I can assure you that the behavior is identical regardless of where you call the method. Try it:

git clone --single-branch -b hugo-forum-topic-47466 https://github.com/jmooring/hugo-testing hugo-forum-topic-47466
cd hugo-forum-topic-47466
hugo server

Yes you are right : the fact is that when I build your example or my development for my site in local with “hugo server” command, there is “/-at-the-end-links” everywhere : so the templates and all in Hugo are coherent ! (sorry)

When we deploy in standard on Render, the sitemaps remains as it is built: with /-at-the-end-links but the “/” at the end of internal links are removed (by Render to be clear) !

The only solution I found now is to add in rewrite/redirect rules in Render the rule (I write that for any in my case) : a rewrite rule , so all the links are served with a “/” at the end.
Capture d’écran_2025-06-23_03-51-26

the pages stored in GG with no “/” will remain some months without being redirected in 301 for the moment but at least the cause is taken at root.
I will post asa I get a solution by Render .

If true, that’s a render.com behavior that violates the principle of least surprise. If it were me, I’d host elsewhere.

yes , it would be a solution to move the hosting, but the bad is done, I have to recover the bad links now. I am pretty sure to find other bugs with the others.

I try to find with them a solution : they have the link of this discussion in my support request, and I think that their reputation is also important and they will find a solution as they always did before. I saw this good technical discussions appears many years after in the logs of Google !

I even find the way to have the last version of Hugo hosted (not simple I agree, but I have).

Do you have please a simpler way to find the 301 answer than postman ?

it was true until yesterday before I added the rewrite rule

sorry, it remains 2 problems for me , in dev , at built stage :

  • in the hugo.toml, I have to end my baseURL with a “/” (it was not) ?
  • even after that the link of the logo is not ending with a “/” (header.hlml) : the code is :
<a class="text-gray-800 text-xl" href="{{ site.BaseURL | relLangURL }}">
        {{ if site.Params.logo }} 
        <img src="{{ site.Params.logo | absURL }}" alt="{{ site.Title }}" {{with site.Params.logo_width}}width="{{.}}"{{end}}>
        {{ else }} 
        {{ site.Title }} 
        {{ end }}
      </a>

I do not find any error for me.

The baseURL in your site configuration should be:

https://www.productivix.com/

If you want to create a link to home page:

{{ site.Home.RelPermalink }}

or 

{{ site.Home.Permalink }}

If you have additional questions please open a new topic.