Is there a way to remove the .html extensions in Hosting Firebase?

橙三吉。 提交于 2021-02-08 09:59:11

问题


I found in the firebase documents that you could hide the .html extensions of my site by creating a "firebase.json" file. I effectively remove the extensions but when I want to enter my other pages I cannot. I always see the main page.

I tried previously with .htaccess but it didn't work out. Now I found this firebase resource but any extension directs me to the main page.

I put that in my file "firebase.json"

"hosting": {

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

回答1:


You can set up routes inside of firebase.json. They can either be rewrites (where the url is actually pointing to another location, but that is unknown to the user), or redirects (where the page redirects to another url).

Inside of your firebase.json, hosting should look like this:

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

There are 2 added nodes, rewrites and redirects. What this does is whenever someone visits /sign-up, you actually point them to /sign-up.html, where your actual html code is. But when someone visits /sign-up.html on their own, you redirect them to /sign-up.



来源:https://stackoverflow.com/questions/57332661/is-there-a-way-to-remove-the-html-extensions-in-hosting-firebase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!