在 Firebase Hosting SPA + 2 个子文件夹上配置重定向 firebase.json
Configure redirects on Firebase Hosting SPA + 2 subfolders firebase.json
我有一个 public 文件夹,例如:
/public
index.html
/landing
index.html
/membership
index.html
/public/index.html 是一个 SPA,所以对 /** 的每个请求都应该重写为 /index.html
/landing/ 和 /membership/ 是两个静态 HTML 登陆,因此不应重写每个请求
firebase.json 建议 Google 支持:
{
"functions": {
"source": "functions"
},
"hosting": {
"public": "public",
"redirects": [{
"source": "/landing",
"destination": "index.html"
},
{
"source": "/membership",
"destination": "index.html"
}
],
"rewrites": [{
"source": "/membership/**",
"destination": "/membership/index.html"
}
],
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
}
}
一切都被重定向到 /index.html...
甚至尝试过:
{
"functions": {
"source": "functions"
},
"hosting": {
"public": "public",
"redirects": [{
"source": "/landing/**",
"destination": "/landing/index.html"
},
{
"source": "/membership/**",
"destination": "/membership/index.html"
}
],
"rewrites": [{
"source": "**",
"destination": "/index.html"
}
],
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
}
}
相同的结果,所有内容都转到 /
您不必使用 "redirects"。
只需使用这些重写规则:
{
"functions": {
"source": "functions"
},
"hosting": {
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "!/@(landing|membership)/**",
"destination": "/index.html"
},
{
"source": "/landing/**",
"destination": "/landing/index.html"
},
{
"source": "/membership/**",
"destination": "/membership/index.html"
}
]
}
}
第一条规则将重写除以着陆或会员资格开头的所有内容。
第二条规则将处理着陆路径。
第三个将指定如何处理所有成员资格路径。
我有一个 public 文件夹,例如:
/public
index.html
/landing
index.html
/membership
index.html
/public/index.html 是一个 SPA,所以对 /** 的每个请求都应该重写为 /index.html
/landing/ 和 /membership/ 是两个静态 HTML 登陆,因此不应重写每个请求
firebase.json 建议 Google 支持:
{
"functions": {
"source": "functions"
},
"hosting": {
"public": "public",
"redirects": [{
"source": "/landing",
"destination": "index.html"
},
{
"source": "/membership",
"destination": "index.html"
}
],
"rewrites": [{
"source": "/membership/**",
"destination": "/membership/index.html"
}
],
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
}
}
一切都被重定向到 /index.html...
甚至尝试过:
{
"functions": {
"source": "functions"
},
"hosting": {
"public": "public",
"redirects": [{
"source": "/landing/**",
"destination": "/landing/index.html"
},
{
"source": "/membership/**",
"destination": "/membership/index.html"
}
],
"rewrites": [{
"source": "**",
"destination": "/index.html"
}
],
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
}
}
相同的结果,所有内容都转到 /
您不必使用 "redirects"。 只需使用这些重写规则:
{
"functions": {
"source": "functions"
},
"hosting": {
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "!/@(landing|membership)/**",
"destination": "/index.html"
},
{
"source": "/landing/**",
"destination": "/landing/index.html"
},
{
"source": "/membership/**",
"destination": "/membership/index.html"
}
]
}
}
第一条规则将重写除以着陆或会员资格开头的所有内容。 第二条规则将处理着陆路径。 第三个将指定如何处理所有成员资格路径。