Open divinerites opened 6 years ago
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.
If this is a bug and you can still reproduce this error on the master
branch, please reply with all of the information you have about it in order to keep the issue open.
If this is a feature request, and you feel that it is still relevant and valuable, please tell us why.
This issue will automatically be closed in the near future if no further activity occurs. Thank you for all your contributions.
Still present in Hugo v0.53.
temporary workaround:
NODE_ENV=production hugo -v && cp public/ru/404.html public/404.htm
I believe this issue is absolutely relevant. You need to use some nasty hacks otherwise.
Would be nice to know if the "hack" is currently the recommended method to use.
I think this is not a simple problem that can be addressed with a cp hack. refer to #3075. Some multilingual sites may want to have 404 pages in different languages. This involves in-site routing, and is not solvable with a single-languaged global 404.
For example, if I have a site with all English content under /en/ and their Chinese counterparts under /zh/. If a user accessed sth. not existed under /zh/, we want to present a Chinese 404 page, and in that page, all links (eg. home/section navs) should all be pointed still to pages under /zh/. The same goes for English pages. Apparently, in this case, showing either an English or Chinese global 404 page may mess up the in-site routing.
I personally think this is something need to be addressed by the server, and hugo (as a static site generator) can hardly do anything about it.
I became aware of this issue today.
Actually there is a much simpler way than what was posted above.
Generate the project locally and then simply copy the 404.html from the language directory under /static/.
The staticDir
by default lives outside Hugo’s Multilingual Mode, therefore a 404.html under the root of /static/
will be served under the root of the domain without having to use any shell command during deployment.
Generate the project locally and then simply copy the 404.html from the language directory under /static/.
I guess this will lead to problems as soon as asset URLs will change? You would need to update your static 404.html
copy each time the site is rebuilt to ensure it still references valid assets.
Fair enough @Guite
I tested further and found that one can simply set the url
parameter with a forward slash at the beginning, so that Hugo outputs the page under the host root, even if the project uses defaultContentLanguageInSubdir = true
e.g. url = "/404.html"
I believe that this is a non-issue that it can be closed, since it is dead easy to output the 404 page at the root.
cc: @divinerites
@onedrawingperday where do you define this url
parameter? Does this require creating the 404
page within content/
explicitly? please elaborate.
@Guite
Yes. Simply create a 404.md and include the above in its front matter.
Nice solution, thank you.
@bep Can you look into this strange behavior? This has been stale for quite some time but could be fixed in a short time. A similar case worth mentioning is #5160, but for robots.txt
. I'm unfamiliar with golang, so I'm not sure how to work on this problem, but if you can give some direction and hints, I can help work on this bug.
For 404 in multilingual site. I have this idea
just successfully managed to get a custom multilanguage 404 page to show up in my Vercel deployment with this setup:
themes/<theme-name>/layouts/404.html
T
function (example: {{ "pageNotFound" | T }}
)en
and it
languages set up, so when deploying this template will generate both public/en/404.html
and public/it/404.html
vercel.json
{
"routes": [
{ "handle": "filesystem" },
{ "src": "/en/(.*)", "status": 404, "dest": "/en/404.html" },
{ "src": "/it/(.*)", "status": 404, "dest": "/it/404.html" },
{ "src": "/(.*)", "status": 404, "dest": "/en/404.html" }
]
}
/en/unknown-page
will show the English 404 page, while /it/unknown-page
will show the Italian one; the English one is used as fallback for all URLs that do not start with any language code)I summarized three workarounds to this issue in a blog post: Create Top-Level 404 Page for a Multilingual Hugo Site. I hope it will be helpful.
In the direct relation with #5160 I open this (related ?) issue.
When option defaultContentLanguageInSubdiris set to true, a sitemap.xml file is automagically generated by Hugo at the root of the website, as well as in all language subdirectories.
I propose that the same is done for the 404.html file, which is currently (as of Hugo 0.48) only generated in language subdirectories but not at the root of the website.
See :
https://discourse.gohugo.io/t/404-html-not-generated-on-root-if-defaultcontentlanguageinsubdir-true/14048