Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I implement a .htaccess configuration in Firebase Hosting?

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?

like image 464
dreezyA Avatar asked Sep 09 '17 12:09

dreezyA


Video Answer


1 Answers

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"
  } ]
}
like image 137
Mariano Córdoba Avatar answered Oct 19 '22 12:10

Mariano Córdoba