10

I have in my domain a .htaccess configuration that allows my app to work perfectly with the routes. It avoids the error when you refresh an angular 2 app can't resolve the routes.

My current config is this one

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

I'm trying to implement the same configuration in my Firebase Hosting because I'm migrating my site, I don't know how to translate from .htaccess to Firebase Hosting configuration.

Is there any simple way to do it?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
dreezyA
  • 111
  • 2
  • 9

1 Answers1

16

You can't use .htaccess in Firebase hosting, but you can configure it to rewrite, redirect, cache, etc.

Learn how to customize hosting behavior here.

Your .htaccess would be translated to

"hosting": {
  "rewrites": [ {
    "source": "**/!(*.css|*.js|*.map|*.jpg|*.gif|*.png|*.php)",
    "destination": "/index.html"
  } ]
}
Mariano Córdoba
  • 1,097
  • 1
  • 13
  • 29
  • Thank you so much. This works perfectly, now I have to test if all my .php files are allowed to write in the domain. – dreezyA Sep 12 '17 at 04:23
  • 2
    Is it possible to use the same principle to just enable all CORS in Friebase Hosing? – Stein. Feb 23 '20 at 10:37