Open Fei927 opened 2 months ago
Which 404 page gets served depends on your server. Most servers send /404.html
whenever they receive a request to a nonexistent route. If you want to make it serve /fr/404.html
, you have to configure your server to redirect all /fr/*
to /fr/404.html
. For example, check out https://github.com/facebook/docusaurus/blob/main/website/static/_redirects. This is going to be different for each server.
Maybe we can add this to the docs.
Which 404 page gets served depends on your server. Most servers send
/404.html
whenever they receive a request to a nonexistent route. If you want to make it serve/fr/404.html
, you have to configure your server to redirect all/fr/*
to/fr/404.html
. For example, check out https://github.com/facebook/docusaurus/blob/main/website/static/_redirects. This is going to be different for each server.Maybe we can add this to the docs.
What should I do if I don't use a hosting service?
What are you using?
What are you using?
I deployed docusaurus directly on my local machine without using a web hosting service.
Yes we should document this. Not easy though because we can't write a full guide to all the existing hosting platforms. But we can give a few generic hosting recommendations.
I also want to give a few tips like setting caching headers for assets, leveraging Webpack persistent caching etc... Not sure where to put that, the deployment page is already quite messy and long. Maybe we need a whole sidebar category just for deployment?
I deployed docusaurus directly on my local machine without using a web hosting service.
What does "deployed" mean, you must be running something on your local machine. docusaurus serve
CLI is a possibility but there are many others including Apache, Nginx, arnish, http-server, serve...
You should read the doc of the tool you use, and see if it's possible to redirect 404 reponses to the /<locale>/404.html
file.
Note that docusaurus serve
is not particularly the best option, as we document here: https://docusaurus.io/docs/deployment#self-hosting
I don't think we expose any way to serve the localized 404 page, but that could be an interesting thing to add automatically. This is the lib we use under the hood and it supports rewrites: https://github.com/vercel/serve-handler
If you use something else, you'd have to figure it out because we don't provide support for anything else than docusaurus serve
.
Yes we should document this. Not easy though because we can't write a full guide to all the existing hosting platforms. But we can give a few generic hosting recommendations.
I also want to give a few tips like setting caching headers for assets, leveraging Webpack persistent caching etc... Not sure where to put that, the deployment page is already quite messy and long. Maybe we need a whole sidebar category just for deployment?
I deployed docusaurus directly on my local machine without using a web hosting service.
What does "deployed" mean, you must be running something on your local machine.
docusaurus serve
CLI is a possibility but there are many others including Apache, Nginx, arnish, http-server, serve...You should read the doc of the tool you use, and see if it's possible to redirect 404 reponses to the
/<locale>/404.html
file.Note that
docusaurus serve
is not particularly the best option, as we document here: https://docusaurus.io/docs/deployment#self-hostingI don't think we expose any way to serve the localized 404 page, but that could be an interesting thing to add automatically. This is the lib we use under the hood and it supports rewrites: https://github.com/vercel/serve-handler
If you use something else, you'd have to figure it out because we don't provide support for anything else than
docusaurus serve
.
OK, I understand. I use docusaurus serve. I will follow your advice and adjust my website according to the deployment section in the document. Thank you!
Maybe you can consider adding why you need a hosting service and the advantages of using a hosting service in the deployment document. This is just a suggestion.
Thanks for your reply!
@slorber Hello! I am trying to solve this issue for my website. I want to know whether this _redirects
file works with GitPage. I have attempted to configure it like this
https://github.com/cainmagi/dash-json-grid/blob/docs/static/_redirects
Unfortunately, I found that it seems to not work:
https://cainmagi.github.io/dash-json-grid/zh-cn/docs/apis/x
(This page is still redirected to 404
, not zh-cn/404
.)
I also have a main site repository for cainmagi.github.io
. I do not know whether it does not work because I did not configure the same file for that main site repo. Currently, It is not very convenient for me to update my main site (it has not been updated for several years), so I want to know if you can give me any suggestions?
Thank you!
The _redirects
file is something specific to your host. Afaik only Netlify and Cloudflare Pages support this
Other hosts expose other ways to achieve the same, but you'll have to read your host docs for that. I don't know anything about GitPage. If you meant "GitHub Pages", it doesn't have a way to do server redirects so it's technically not possible on this host (I don't particularly recommend it, others are better).
The
_redirects
file is something specific to your host. Afaik only Netlify and Cloudflare Pages support thisOther hosts expose other ways to achieve the same, but you'll have to read your host docs for that. I don't know anything about GitPage. If you meant "GitHub Pages", it doesn't have a way to do server redirects so it's technically not possible on this host (I don't particularly recommend it, others are better).
Yes, I mean GitHub Pages. Thank you for letting me know it! I will keep it as it is now.
Have you read the Contributing Guidelines on issues?
Description
How can docusaurus' 404 page be adapted to other language pages?
When I switch to other languages, such as French, I find that the 404 page cannot be switched to French, and the language switch box does not respond. Is there any way to make the 404 page change with the language switch?
Self-service