A redirect rule sends visitors from one URL to another URL automatically. It changes the address shown in the browser.
Click to reveal answer
beginner
What does a rewrite rule do in Firebase Hosting?
A rewrite rule serves content from a different location without changing the URL in the browser. It keeps the original URL visible.
Click to reveal answer
intermediate
How do you define a redirect rule in Firebase Hosting configuration?
You add a 'redirects' section in firebase.json with 'source' (the URL to match) and 'destination' (where to send users), plus a 'type' for HTTP status code.
Click to reveal answer
intermediate
Why use rewrite rules for single-page applications (SPA)?
Rewrite rules send all URL requests to the SPA's main index.html file, so the app can handle routing internally without server errors.
Click to reveal answer
beginner
What HTTP status code is commonly used for permanent redirects in Firebase?
The HTTP status code 301 is used for permanent redirects, telling browsers and search engines the change is permanent.
Click to reveal answer
In Firebase Hosting, what happens when you set a rewrite rule?
AThe site reloads with a 404 error
BThe browser URL changes to the new destination
CThe user is blocked from accessing the site
DThe URL in the browser stays the same but content is served from another location
✗ Incorrect
Rewrite rules serve content from a different location without changing the browser's URL.
Which section in firebase.json defines redirect rules?
Aheaders
Bredirects
Crewrites
Dfunctions
✗ Incorrect
Redirect rules are defined under the 'redirects' section in firebase.json.
What HTTP status code should you use for a temporary redirect in Firebase?
A301
B404
C302
D500
✗ Incorrect
302 is the HTTP status code for temporary redirects.
Why are rewrite rules important for SPAs hosted on Firebase?
AThey allow the app to handle routing without server errors
BThey block unwanted users
CThey speed up image loading
DThey change the URL to a new domain
✗ Incorrect
Rewrite rules send all requests to index.html so the SPA can manage routing internally.
Which Firebase Hosting feature changes the URL shown in the browser?
ARedirect rules
BRewrite rules
CHeaders
DCaching
✗ Incorrect
Redirect rules change the browser URL to the new destination.
Explain the difference between redirect and rewrite rules in Firebase Hosting.
Think about what the user sees in the browser address bar.
You got /4 concepts.
Describe how you would configure Firebase Hosting to support a single-page application using rewrite rules.
Consider how SPAs handle navigation internally.
You got /4 concepts.
Practice
(1/5)
1. What is the main difference between a redirect and a rewrite in Firebase Hosting?
easy
A. Redirect changes the browser URL, rewrite does not change the URL shown.
B. Rewrite changes the browser URL, redirect does not change the URL shown.
C. Both redirect and rewrite always change the browser URL.
D. Neither redirect nor rewrite affect the browser URL.
Solution
Step 1: Understand redirect behavior
A redirect sends the user to a new URL and updates the browser address bar to show this new URL.
Step 2: Understand rewrite behavior
A rewrite serves different content but keeps the original URL visible in the browser address bar.
Final Answer:
Redirect changes the browser URL, rewrite does not change the URL shown. -> Option A
2. Which of the following is the correct Firebase Hosting syntax to redirect from /old-page to /new-page?
easy
A. "redirect": [{"source": "/old-page", "destination": "/new-page"}]
B. "rewrites": [{"source": "/old-page", "destination": "/new-page"}]
C. "rewrites": [{"source": "/old-page", "type": 301, "destination": "/new-page"}]
D. "redirects": [{"source": "/old-page", "destination": "/new-page", "type": 301}]
Solution
Step 1: Identify redirect syntax
Redirects require a source, destination, and a type (like 301 for permanent redirect).
Step 2: Check options for correct syntax
"redirects": [{"source": "/old-page", "destination": "/new-page", "type": 301}] correctly includes source, destination, and type 301. Others miss type or use rewrites incorrectly.
Final Answer:
"redirects": [{"source": "/old-page", "destination": "/new-page", "type": 301}] -> Option D
Quick Check:
Redirect needs type code like 301 [OK]
Hint: Redirects need a type code (301 or 302) [OK]
Common Mistakes:
Omitting the redirect type code
Using rewrites instead of redirects for URL change
But the redirect does not work as expected. What is the problem?
medium
A. Using redirects instead of rewrites for serving index.html.
B. The source path should be /home/** to match all subpaths.
C. Missing the redirect type (301 or 302) in the redirect rule.
D. The destination should be a full URL, not a relative path.
Solution
Step 1: Analyze the redirect behavior
A redirect requires a type (301 or 302) to work properly. Missing the type causes the redirect to fail.
Step 2: Identify the likely expectation and fix
Adding the redirect type (301 or 302) will fix the redirect. Using rewrites is an alternative if you want to serve content without changing the URL.
Final Answer:
Missing the redirect type (301 or 302) in the redirect rule. -> Option C
Quick Check:
Redirect requires type code [OK]
Hint: Redirects need a type code (301 or 302) [OK]
Common Mistakes:
Using redirects instead of rewrites to preserve URL
Confusing redirects with rewrites
Using relative paths incorrectly
5. You want to support a single-page app on Firebase Hosting where all URLs under /app/ show index.html content without changing the URL, but also redirect /old-app permanently to /app/. Which config snippet correctly achieves this?