提问人:ttoshiro 提问时间:6/15/2020 最后编辑:ttoshiro 更新时间:6/24/2020 访问量:3472
如何在Firebase中删除.html URL结尾并配置重定向?
How to remove .html URL endings and configure redirects in Firebase?
问:
编辑:修复了一个错误,我在HTML中引用了该错误,但仍然遇到相同的问题。about.html
/about/
我知道这是以前被问过很多次的问题的重复,但其他人的解决方案对我不起作用。我试图做的是重新路由,例如,到 和 到 .index.html
/index/
about.html
/about/
我尝试在这里使用 @louisvno 的答案,在这里使用 @michael-bleigh 的答案,在这里使用 @HarsH 的答案,所有这些都是为了将以下内容添加到 .json 文件中:
"hosting": {
"cleanUrls": true
}
(这也是Firebase配置托管行为指南的“控制.html扩展”部分的答案。)
但是,这没有效果。在我的 HTML 文件中,我尝试将标签设置为 、 和 ,但这些选项都不起作用,我不确定是否有必要从原始更改它。(是吗?<a>
href="index.html
href="/index/
href="/index"
<a href="index.html">
我尝试的另一个解决方案是利用该属性,正如 @ken-mueller 在这里建议的那样。我删除了“clearUrls”位,并将以下内容放在我的.json文件中:"redirects"
"hosting": {
"redirects": [ {
"source": "index.html",
"destination": "/index",
"type": 301
}, {
"source": "index.html{,/**}",
"destination": "/index",
"type": 3011
}, {
"source": "about.html",
"destination": "/calculator",
"type": 301
}, {
"source": "about.html{,/**}",
"destination": "/solutions",
"type": 301
} ]
}
(这也是 Firebase 配置托管行为指南的“配置重定向”部分的答案)
这也没有任何效果。而且,即使将我的 HTML 从 更改为 或 ,它也只是破坏了页面并显示页面。<a href="about.html">
<a href="/about/">
<a href="/about">
about.html
index.html
我做错了什么?如何从 URL 末尾删除 .html 并确保在 URL 中输入任何时候它都会重定向到没有结尾的 URL(即 而不是?/index/
/index.html
答:
最终解决了这个问题,这要归功于 Firebase 支持的 Mau。 工作正常,我只需要一个开括号和闭合括号(呃)。对于我帖子中的代码,我还注意到其中一个重定向已设置为而不是 .无论哪种方式,最终代码都是:"cleanUrls"
"type":
3011
301
{
"hosting": {
"cleanUrls": true,
"trailingSlash": true
}
}
评论
"cleanUrls": true
.html
/index.html
/index
/
https://carbonfootprint.dev/calculator.html
https://carbonfootprint.dev/calculator
/calculator
calculator.html