【问题标题】:Is there a way to remove the .html extensions in Hosting Firebase?有没有办法删除 Hosting Firebase 中的 .html 扩展名?
【发布时间】:2019-08-02 19:50:17
【问题描述】:

我在 firebase 文档中发现,您可以通过创建“firebase.json”文件来隐藏我网站的 .html 扩展名。我有效地删除了扩展,但是当我想进入我的其他页面时,我不能。我总是看到主页。

我之前尝试过使用 .htaccess,但没有成功。现在我找到了这个 firebase 资源,但任何扩展都会将我引导到主页。

我把它放在我的文件“firebase.json”中

"hosting": {

  "cleanUrls": true,
  "trailingSlash": false
}

【问题讨论】:

    标签: firebase firebase-hosting


    【解决方案1】:

    您可以在firebase.json 内设置路由。它们可以是rewrites(网址实际上指向另一个位置,但用户不知道)或redirects(页面重定向到另一个网址)。

    您的firebase.jsonhosting 内部应如下所示:

    "hosting": {
        "public": "public",
        "ignore": [
            "firebase.json",
            "**/.*",
            "**/node_modules/**"
        ],
        "rewrites": [
            {
                "source": "/sign-up",
                "destination": "/sign-up.html"
            }
        ],
        "redirects": [
            {
                "source": "/sign-up.html",
                "destination": "/sign-up"
            }
        ]
    }
    

    添加了 2 个节点,rewritesredirects。这样做是每当有人访问/sign-up 时,您实际上将他们指向/sign-up.html,即您的实际html 代码所在的位置。但是当有人自己访问/sign-up.html 时,您会将他们重定向到/sign-up

    【讨论】:

    • "hosting": { "cleanUrls": true, "trailingSlash": false, "public": "public", "ignore": [ "firebase.json", "**/.*", "**/node_modules/**" ], "rewrites": [ { "source": "/proyectos", "destination": "/proyectos.html" } ], "redirects": [ { "source": "/proyectos.html", "destination": "/proyectos" } ] } 那是我的firebase.json 代码,您可以在 [link](xmobiliario.com) 中查看我的页面 它没有修复
    • 您是否尝试过清除浏览器的缓存?在 chrome macOS 上,按 Cmd+y 并在左侧单击“清除浏览数据”,只选择清除缓存。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-15
    • 1970-01-01
    • 2012-10-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多