【问题标题】:How can I implement a .htaccess configuration in Firebase Hosting?如何在 Firebase 托管中实现 .htaccess 配置?
【发布时间】:2017-09-09 12:19:14
【问题描述】:

我在我的域中有一个 .htaccess 配置,它允许我的应用程序与路由完美配合。它避免了刷新 Angular 2 应用程序无法解析路由时的错误。

我当前的配置是这个

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# not rewrite css, js and images
RewriteCond %{REQUEST_URI} !\.(?:css|js|map|jpe?g|gif|png|php)$ [NC]
RewriteRule ^(.*)$ /index.html?path=$1 [NC,L,QSA]
</IfModule>

我正在尝试在我的 Firebase 托管中实现相同的配置,因为我正在迁移我的网站,我不知道如何从 .htaccess 转换为 Firebase 托管配置。

有什么简单的方法吗?

【问题讨论】:

    标签: firebase hosting firebase-hosting


    【解决方案1】:

    .htaccess不能在Firebase hosting中使用,但可以配置为重写、重定向、缓存等。

    在此处了解如何customize hosting behavior。

    您的.htaccess 将被翻译成

    "hosting": {
      "rewrites": [ {
        "source": "**/!(*.css|*.js|*.map|*.jpg|*.gif|*.png|*.php)",
        "destination": "/index.html"
      } ]
    }
    

    【讨论】:

    • 非常感谢。这很好用,现在我必须测试是否允许我所有的 .php 文件在域中写入。
    • 是否可以使用相同的原理只启用 Friebase Hosing 中的所有 CORS?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-01
    • 1970-01-01
    相关资源
    最近更新 更多