【问题标题】:How to remove .php extension on firebase hosted webpage?如何删除 Firebase 托管网页上的 .php 扩展名?
【发布时间】:2021-12-29 08:21:06
【问题描述】:

我在使用 firebase 托管的网页上重写 url 时遇到问题。 这就是我的 firebase.json 的样子。



{
  "hosting": {
    "cleanUrls": true,
    "trailingSlash": true,
    "headers": [ {
      "source": "*.php",
      "headers": [ {
        "key": "Content-Type",
        "value": "text/html"
      } ]
    } ],
    "appAssociation": "AUTO",
    "public": "public",
    "rewrites": [
      {
        "source": "**/!(*.css|*.js|*.map|*.jpg|*.gif|*.png|*.php),/post/**",

        "dynamicLinks": true
       
      }
    ]

  }
}

到目前为止一切顺利。我遇到的问题不起作用。 例如,当我的网页托管在 https://google.com

上时

我的内部联系页面目前在https://google.com/contact.php

这行得通,但那行不通https://google.com/contact 但这就是我想要的。另外,也许您可​​以检查我是否正确并给出了 2 条重写规则,第一个规则是这样的

"**/!(*.css|*.js|*.map|*.jpg|*.gif|*.png|*.php)",

第二个是这个

/post/**

我可以一起写还是应该自己重写标签

/post/**

【问题讨论】:

  • Firebase 托管不提供/解释 PHP 代码。您确定文件扩展名是您的主要问题吗?
  • 是的,它使用 Headers Firebase firebase 将 php 代码读取为 html 我认为 stackoverflow.com/questions/61963981/…。所以它有效,我可以看到它有效。但我不知道为什么仍然没有 .php 网络服务器找不到页面

标签: php html firebase url-rewriting firebase-hosting


【解决方案1】:

Firebase 托管提供的最接近的选项是您已经设置的 "cleanUrls": true 选项。但这只会删除 .html 扩展名。这是设计使然,因为.html 文件通常作为静态内容提供,其完整 URL 会显示在浏览器中。

Firebase 托管不会以任何方式解释 PHP 代码,因此很可能它会将您的 PHP 代码作为纯文本提供给您的网站访问者。如果您的文件中没有 PHP 代码,请将它们重命名为 .html,此时 "cleanUrls": true 选项将删除扩展名。

【讨论】:

  • van Puffeln 正如我所说,我首先使用 php 代码,它显示为纯文本,但现在标题标签显示正确。因为 headers 标签将其重写为 html。但是 .php 扩展名仍然存在。
猜你喜欢
  • 1970-01-01
  • 2021-02-01
  • 2017-07-24
  • 1970-01-01
  • 1970-01-01
  • 2013-01-09
  • 1970-01-01
  • 2017-01-16
  • 1970-01-01
相关资源
最近更新 更多