Firebase

How to configure Firebase Hosting with custom error pages?

Discover how to customize error pages on Firebase Hosting with this detailed guide. Follow a step-by-step process, pick up best practices, and get handy tips and troubleshooting advice.

Developer profile skeleton
a developer thinking

Overview

Tailoring error pages on Firebase Hosting makes for a friendlier user experience when something goes wrong. You'll need to create and upload your own error page, then tell Firebase how to use it. Basic knowledge of Firebase, HTML, CSS (for your custom error pages), and YAML (for tweaking the firebase.json settings) is essential. This guide will take you through each step to set up your custom error pages with Firebase Hosting.

Get a Free No-Code Consultation
Meet with Will, CEO at Bootstrapped to get a Free No-Code Consultation
Book a Call
Will Hawkins
CEO at Bootstrapped

How to configure Firebase Hosting with custom error pages?

Step 1: Install Firebase CLI

Alright, let's kick things off by getting the Firebase CLI (Command-Line Interface) tool installed. This is our gateway to Firebase Hosting. Open up your terminal and type:

npm install -g firebase-tools

Step 2: Initialize Firebase Project

Next up, we need to set up our Firebase project in the local directory. Fire up your terminal again and log in to Firebase using your Google account by typing:

firebase login

Once you're logged in, initialize your Firebase project with:

firebase init

During this setup, choose Hosting. You'll need to configure your public directory (where your website’s files live) and decide if you want to use single-page app routing.

Step 3: Create Your Error Page

Now, let's create a custom error page. Save this file in your public directory, the same place as your website's index.html. You can name it something like 404.html.

Step 4: Configuring Firebase.JSON for Custom Error Page

In the firebase.json file at the root of your project, we need to tell Firebase Hosting to redirect 404 errors to our custom error page. Add this code:

{
  "hosting": {
    "public": "public",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/404.html"
      }
    ]
  }
}

This setup tells Firebase Hosting to send all requests for non-existent static files to the /404.html page.

Step 5: Deploy to Firebase Hosting

Your website is now ready to roll with Firebase, complete with its custom error page. Deploy your site by running:

firebase deploy

After deploying, Firebase will give you a unique URL. Test it out by adding a path that you know doesn't exist, and make sure Firebase shows your custom 404 error page.

Explore more Firebase tutorials

Complete Guide to Firebase: Tutorials, Tips, and Best Practices

Explore our Firebase tutorials directory - an essential resource for learning how to create, deploy and manage robust server-side applications with ease and efficiency.

Why are companies choosing Bootstrapped?

40-60%

Faster with no-code

Nocode tools allow us to develop and deploy your new application 40-60% faster than regular app development methods.

90 days

From idea to MVP

Save time, money, and energy with an optimized hiring process. Access a pool of experts who are sourced, vetted, and matched to meet your precise requirements.

1 283 apps

built by our developers

With the Bootstrapped platform, managing projects and developers has never been easier.

hero graphic

Our capabilities

Bootstrapped offers a comprehensive suite of capabilities tailored for startups. Our expertise spans web and mobile app development, utilizing the latest technologies to ensure high performance and scalability. The team excels in creating intuitive user interfaces and seamless user experiences. We employ agile methodologies for flexible and efficient project management, ensuring timely delivery and adaptability to changing requirements. Additionally, Bootstrapped provides continuous support and maintenance, helping startups grow and evolve their digital products. Our services are designed to be affordable and high-quality, making them an ideal partner for new ventures.

Engineered for you

1

Fast Development: Bootstrapped specializes in helping startup founders build web and mobile apps quickly, ensuring a fast go-to-market strategy.

2

Tailored Solutions: The company offers customized app development, adapting to specific business needs and goals, which ensures your app stands out in the competitive market.

3

Expert Team: With a team of experienced developers and designers, Bootstrapped ensures high-quality, reliable, and scalable app solutions.

4

Affordable Pricing: Ideal for startups, Bootstrapped offers cost-effective development services without compromising on quality.

5

Supportive Partnership: Beyond development, Bootstrapped provides ongoing support and consultation, fostering long-term success for your startup.

6

Agile Methodology: Utilizing agile development practices, Bootstrapped ensures flexibility, iterative progress, and swift adaptation to changes, enhancing project success.

Yes, if you can dream it, we can build it.