I’m building a multilingual site and would like to have 2 different urls for my section list page.
The content is as follows:
Currently, by default, hugo generates
/product/product-1 which is expected.
For multilingual purpose, I want to achieve:
I can achieve
permalinks configuration in
config.toml but I don’t know how to generate
/produit one which will still use my section template page under theme//layouts/section/product.html (same for both language).
Any idea would be very appreciated.
Thanks a lot.
P/S: I tried with putting
slug in _index.md and that seems not working although the content of the file is picked up correctly in the template.
I don’t think what you want is currently possible (but please prove me wrong).
But I agree that it would be useful. I have a two-language blog, and I have “solved” this problem by creating short and language agnostic sections ("/prod/" in your example).
For Hugo 0.21 we plan to add nested sections, and I will have this in the back of my head. Please also create a GitHub issue to track it.
So I “solved” this by:
- Override permanlinks of “product” section in
config.toml file by
product = "/produit/:slug"
- Add alias for section URL by putting this into _index.md file
aliases = ["/produit"]
This way, it’s guaranteed that
/produit/produit-1 both works. For English language, I don’t do anything so by default
/product/product-1 should work.
In my opinion, this is not a recommended way though, just some workaround to make sure even I give
https://example.com/fr/produit link to customer, it still works (by redirecting back to
/product which is okay for now).
Still, clean and native solution from Hugo would be hugely appreciated.
I’m currently facing the same issue. I saw that there were no updates on Github about this. Did anyone find another solution for this?
Did anyone find a way to override the section URL? I’m working on a single-language website, and would like to override the top sections (the slugs of the subsections are fine).
Any ideas or suggestions are more than welcome.
The best way I can think is by using redirects. See this recent thread on redirects that has Netlify and htaccess redirect examples.
Yeah, that’s an option, but for SEO and website speed I’d rather not use too many redirects.
I’m probably not getting the full picture as I am thinking “if you want to just change the section URL, why not just rename the section”?
Can you give examples of what the urls of the said section and nested posts look like now, and what you want them to look as instead?
Say someone writes posts about ox-hugo, and has the following content files:
Because ox-hugo might not be a term a lot of people are searching for, it might make sense to add a few extra keywords to the main page. So instead of
our fictitious person might want to use
But if we rename the
ox-hugo section to
ox-hugo-org-exporter, all URLs in that section become quite long (too long in my taste).
And so just renaming the section isn’t what I’m interested in.
- So, do you want to alias just
- Or have that alias to also imply aliasing of
If it’s just point 1 above, then I believe (haven’t tried), setting the
aliases in that section’s
_index.md, as mentioned here, should work.
Since I link to the section three times on each page for navigation purposes (header, breadcrumbs, footer), that would create 3 redirected links on each content page. I’m not interested in taking that gamble.
And if I hard code the proper URL in the Hugo templates, building the website fails because
htmltest reports a website check error.
I was suggesting using
aliases, not something like Netlify
_redirects. But I understand that the
aliases approach creates a different kind of redirect, using meta refresh.
So… I’m not sure how else you would solve this… you cannot have symlinks in webpages…
Thanks for thinking along. Other than the
slug front matter variable for the
/ox-hugo/_index.md file working I also don’t know an easy way. I can write a Gulp task to rewrite the HTML files Hugo renders, but that’s tricky since it might break easily.
Perhaps other people have already fixed overriding the section URL.
Hugo v0.33 release notes:
Hugo now respects the url value in front matter for all page types, including sections. Also, you can now configure uglyURLs per section.
Won’t this do the trick? Though there is an unresolved issue with regard to
relref shortcodes not working if you do this.
Wow good catch, that does the trick! Thank you! I tried
slug earlier today (which didn’t work) but overlooked
For others in this thread, you’ll need to use the
url page variable, and not
slug. That looks like this. For example to have the
/ox-hugo/ section main page render at
/ox-hugo-org-exporter/ instead of its default URL, use a front matter like this:
title = "Ox-hugo"
url = "/ox-hugo-org-exporter/"
date = "2018-05-16"
I believe slug did not work because slugs replace the filename part of the path, and for a sections the “_index.md” filename is ultimately stripped away. See Path Breakdown in Hugo.