Link are wrong when i deploy on Netlify

Dear community,

I have some issues with the links that behave differently when I deploy my Hugo website locally and on Netlify, I don’t understand why, but locally it work perfectly fine.

The problem is probably with i18n since I want to make my website multilangual. The issue comes when you click on the EN flag and then try to browse the gallery ( top nav bar )

Description of the problem :

  • After clicking on the english flag and then the gallery button the url use twice the “en” in the URL: patia-78719d.netlify.com/en/en/gallery.
  • After clicking on gallery and then browse it, it duplicate the “gallery” word in the URL.

Here is the source code: Kyliux / blog · GitLab
Here is the page : https://5e5df593c153dc000831d1b9--ecstatic-hypatia-78719d.netlify.com/

Key files are the following

“layout/gallery/branch” for the gallery"
“layout/partial/nav.html” for the navbar"

Any help would be greatly appreciated !

Thank you,

Hi there! It looks like you might be hard-coding the href when clicking the english flag- so you append /en/ to the URL and it stays whenever you click on anything else, and gives you /en/en/gallery instead of /en/gallery (which is what you want). Is it possible to use Hugo’s absLangURL syntax on the english flag button the way you do for the gallery button?

Thank you Jen, I will see if it changes anything.

This being said, I have doubt since when I surf the gallery, I find myself with links like /gallery/gallery/australia, so it’s not the flagname “en” that seems to be repeated but really the middle part of the URL. ( after the .fr et before the last string )

Also I probably need to apologize, am probably coding very clumsily since am still discovering things on Hugo, but I can’t understand why locally it’s working and not on netlify… :confused:

EDIT : Well I think that adding a slash will solve the issue temporarly. I will also rewrite completely the image gallery because it’s not well done.

I will close this threat, thank you.

No apology necessary at all! We’re also always learning new stuff (and making mistakes in the process :sweat_smile:) over here. Thanks for coming back and letting us know what fixed things for you- let us know if we can help with anything else down the road.

Hi jen, I have the same symptoms despite using absLangURL as intended:

{{ i18n “menu_history” }}

I’m linking to an anchor on a single-page website, which - on my local build - results in one of the following URLs depending on the current language:

http://localhost:1313/#history
http://localhost:1313/de/#history

On Netlify, the second link is coming out with a double /de/de despite no hard-coding anywhere:

http://localhost:1313/de/de/#history

Any idea where the second language slug could be coming from?

Hey @mwenglein, could you share your Netlify URL so we can check out your build settings? One thing to check in the meantime is: if you run hugo locally to output your built site, and then view your site in a browser (so, not with hugo server), are the paths correct or do they have the extra path appended?

Hi @jen, on my local build everything is fine, as written above, the links come out with a single language slug as expected when using absLangURL:

http://localhost:1313/#history
http://localhost:1313/de/#history

When using absLangURL on Netlify staging (built from a pull request) everything works perfectly fine, just as in my local environment. The double /de/de only occurs on my live URL.

Btw, my baseURL is set as recommended in your specification:

baseURL = “/”

The repo is private. Please PM or send me an email if you need further details.

Thanks!!

Feels a bit like there’s a redirect on that site. Mind telling us which site you’re working with so we can look at it in place? If you aren’t comfortable sharing your site name, it is safe to share your Site’s API ID, found on the “general settings” page, publicly.

Hi @Jen sorry for not getting back earlier! I had the multi-language temporarily disabled to cover up the issue. However, it’s still unresolved. I’ve reactivated the DE language and my site ID is 32daf64e-becb-4a32-9de6-9f6292cd3538

Not sure what to tell you @michaelwenglein, from Netlify’s perspective, you’re indeed linking it incorrectly:

Is the Hugo version used locally same as that on Netlify?

Yes, it’s the same. And yes, when running locally all is fine, just like your screenshot. Can you reproduce the error in the live site though? It has to happen somewhere during deployment…

Yes

That would be a problem with Hugo then, as Netlify is doing nothing special - just executing the Hugo binary, waiting for it to finish, and deploying the generated files.

We would most likely have to ask for your repo, but debugging on a code-level is usually out of our scope of support.

You can share it with me for now though. GH Username: Hrishikesh-K

Done. It’s two repos, one for the site and one for my fork of the template theme.

The problem is because, in your root config.toml, the base path is /. I changed it to https://www.wenglein.de/ which fixed it.

I’ve opened a PR.

Oh my. Thank you very much and sorry for all the hassle then. Quite obvious indeed…