使用Firebase托管实施本地化的404页面 [英] Implementing localized 404 page with Firebase hosting
问题描述
说我的Web应用程序有两个区域设置:英语(myapp.com/en/
)和法语(myapp.com/fr/
).我想本地化404页面,以便对myapp.com/en/non-existent
或myapp.com/non-existent
的请求将返回英语版本的404页面,而对myapp.comm/fr/non-existent
的请求将返回法语页面.
Say my web app has two locales: English(myapp.com/en/
) and French(myapp.com/fr/
). I want to localize my 404 pages, so that request to myapp.com/en/non-existent
or myapp.com/non-existent
would return an English version of the 404 page and request to myapp.comm/fr/non-existent
would return a French one.
但是,似乎Firebase Hosting默认不提供此类功能,因为它仅允许一个404页(
However, it seems like Firebase Hosting does not provide such functionality by default, as it only allows a single 404 page(source)
那么,有没有一种方法可以使用Firebase Hosting来实现本地化的404页面?
So, is there a way of implementing a localized 404 page with Firebase Hosting?
推荐答案
从2020年8月12日开始,Firebase Hosting现在包括对 i18n内部化.
As of August 12th 2020, Firebase Hosting now includes support for i18n internalization.
这里是使用方法:
- 创建一个新目录,以将这些本地化文件(例如
localized
)托管在您的public
目录下. - 更新您的
firebase.json
文件以包括对该新目录的引用:
- Create a new directory to host these localized files (e.g
localized
) under yourpublic
directory. - Update your
firebase.json
file to include a reference to this new directory:
// firebase.json
"hosting": {
"public": "public",
"ignore": [
// ...
],
"i18n": {
"root": "/localized" // directory that contains your "i18n content"
}
// ...
}
- 在
localized
目录下,创建一个名为fr
的新目录,您可以在其中添加法语404.html
文件. - 运行
firebase deploy
来部署您的网站,现在您的法语用户应该被重定向到正确的页面:)
- Under the
localized
directory, create a new directory namedfr
, and that's where you can add your french404.html
file. - Run
firebase deploy
to deploy your site and now your french users should be redirected to the correct page :)
请参见 Firebase文档有关国家和语言代码的更多信息.
See the Firebase Docs for more information on country and language codes.
这篇关于使用Firebase托管实施本地化的404页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!