有没有办法删除Hosting Firebase中的.html扩展名? [英] Is there a way to remove the .html extensions in Hosting Firebase?

查看:50
本文介绍了有没有办法删除Hosting Firebase中的.html扩展名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在firebase文档中发现,可以通过创建"firebase.json"文件来隐藏网站的.html扩展名.我实际上删除了扩展名,但是当我想输入其他页面时,我不能.我总是看到主页.

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.

我以前用.htaccess尝试过,但没有成功.现在,我找到了该Firebase资源,但是任何扩展都将我定向到主页.

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.

我将其放在文件"firebase.json"中

I put that in my file "firebase.json"

"hosting": {

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

推荐答案

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

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).

在您的 firebase.json 内, hosting 应该如下所示:

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"
        }
    ]
}

添加了2个节点,分别是 rewrites redirects .它的作用是每当有人访问/sign-up 时,您实际上将他们指向/sign-up.html ,即您的实际html代码所在.但是,当有人独自访问/sign-up.html 时,您会将他们重定向到/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.

这篇关于有没有办法删除Hosting Firebase中的.html扩展名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆