13

I am trying to host a website at Google Firebase. The index.html is shown as (e.x.)app.firebase.com, but when I want to access a page like login.html I need to type app.firebase.com/login.html, just app.fire-base.com/login doesn't work. How would I achieve this for every .html file in the directory (public), do I need to configure the firebase.json? I read the docs but I could not find any information.

Here is my .json

 {
      "hosting": {
        "public": "public",
        "signin": "/signin.html"

      }
    }
pessolato
  • 1,472
  • 6
  • 14
  • 1
    I'm not confident enough to give a full answer but I know that when I was deploying applications in firebase with emberjs, the routing (i.e. URLs like /login) was all handled by ember. So I think the reason you can't find anything is because it's the responsibility of your front-end framework. – Cameron May 25 '17 at 06:08
  • i don't use any particular framework i followed the instuctions from getting started and i deployed through nodejs – Stavros Avramidis May 25 '17 at 06:10
  • So this might be a nodejs thing? – Stavros Avramidis May 25 '17 at 06:49

1 Answers1

40

To omit the .html for all resource paths e.g. /login.html -> /login

  • add "cleanUrls": true to your .json.
  • firebase automatically redirects with a 301 code if user enters /login.html.

    "hosting": {
      // ...
    
      // Add the "cleanUrls" attribute within "hosting"
      "cleanUrls": true
    }
    

Read Control .html extensions to know more.


For specific routing: You can make a redirect/rewrite section in your .json as described in the following,

Roshana Pitigala
  • 8,437
  • 8
  • 49
  • 80
louisvno
  • 669
  • 7
  • 17
  • Could you provide an example for login.html , do i need to do this manually for every page? – Stavros Avramidis May 25 '17 at 07:17
  • 3
    Actually this might be better. You want to remove the html for all urls right? To do it for all paths you can add "cleanUrls": true to your json https://firebase.google.com/docs/hosting/full-config#cleanurls This would remove the .html for all urls and automatically redirect for example /login.html to /login – louisvno May 25 '17 at 07:52