gpt4 book ai didi

firebase - Firebase 托管的意外尾部斜杠行为

转载 作者:行者123 更新时间:2023-12-04 21:10:50 24 4
gpt4 key购买 nike

我在 Firebase Hosting 上看到了带有尾部斜杠的意外行为(至少对我而言是这样)。我希望 Firebase 提供带有斜杠的 URL(托管目录中存在的实际文件除外)。为此,我设置了 trailingSlashtrue在 firebase.json 中。

这导致:

example.com                     redirect to     example.com/index.html/
example.com/js/script.js redirect to example.com/js/script.js/
example.com/images/image.png redirect to example.com/images/image.png/

预期的行为是:
example.com                     redirect to example.com/
example.com/js/script.js served as it is without any redirect
example.com/images/image.png served as it is without any redirect

向实际文件 URL 添加尾部斜杠使浏览器/服务器认为 script.js是一个目录而不是文件并导致 404。将 index.html 添加到根目录并不优雅。

期待 cleanUrls做我设置的把戏 cleanUrlstrue连同 trailingSlash并且该站点立即进入无休止的重定向循环并且无法加载。如何阻止 Firebase 在根和实际 js 或图像 Assets 的尾部斜杠添加“index.html”?

编辑:

按照弗兰克的要求,这是我正在使用的 firebase.json:
{
"firebase" : "example",
"public" : "public",
"cleanUrls" : false,
"trailingSlash" : true,
"ignore" : [ "firebase.json", "**/.*", "**/node_modules/**" ],
"rewrites": [{

"source" : "**",
"destination" : "/index.html"

}],
"headers": [{

"source" : "**/*.@(eot|otf|ttf|ttc|woff|font.css)",
"headers" : [{

"key" : "Access-Control-Allow-Origin",
"value" : "*"
}]

}, {

"source" : "**/*.@(jpg|jpeg|gif|png)",
"headers" : [{
"key" : "Cache-Control",
"value" : "max-age=600"
}]

}, {

"source" : "**/*.@(html|js)",
"headers" : [{
"key" : "Cache-Control",
"value" : "max-age=300"
}]

}]
}

P.S.:我试过同时设置 trailingSlashcleanUrlstrue并尝试设置这些 true/false个别。

最佳答案

https://firebase.google.com/docs/hosting/full-config#trailingslash

When true, it will redirect URLs to add a trailing slash. When false it will redirect URLs to remove a trailing slash. When unspecified, trailing slashes are used only for directory index files (e.g. about/index.html).



只是不要添加该选项,它只会影响网址

关于firebase - Firebase 托管的意外尾部斜杠行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35044201/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com