0
0
Firebasecloud~20 mins

Redirect and rewrite rules in Firebase - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Firebase Redirect & Rewrite Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
service_behavior
intermediate
2:00remaining
Understanding Firebase Hosting Redirect Behavior

Given the following Firebase Hosting redirect rule, what will happen when a user visits /old-page?

{
  "hosting": {
    "redirects": [
      {
        "source": "/old-page",
        "destination": "/new-page",
        "type": 301
      }
    ]
  }
}
AThe user gets a 404 error because /old-page no longer exists.
BThe user sees the content of /new-page but the URL stays /old-page.
CThe user is permanently redirected to /new-page with a 301 status code.
DThe user is temporarily redirected to /new-page with a 302 status code.
Attempts:
2 left
💡 Hint

Think about what a 301 redirect means in web hosting.

Configuration
intermediate
2:00remaining
Firebase Hosting Rewrite Rule Effect

Consider this Firebase Hosting rewrite rule:

{
  "hosting": {
    "rewrites": [
      {
        "source": "/app/**",
        "destination": "/index.html"
      }
    ]
  }
}

What happens when a user visits /app/profile?

AThe user is redirected to /index.html and the URL changes to /index.html.
BThe user is served the content of /index.html but the URL remains /app/profile.
CThe user gets a 404 error because /app/profile does not exist.
DThe user is served the content of /app/profile if it exists, otherwise a 404.
Attempts:
2 left
💡 Hint

Rewrite rules serve a file without changing the URL in the browser.

Architecture
advanced
3:00remaining
Combining Redirects and Rewrites in Firebase Hosting

You want to permanently redirect all requests from /blog-old/** to /blog-new/**, but also rewrite all /blog-new/** requests to /blog/index.html for your single-page app. Which configuration achieves this?

A
{
  "redirects": [
    {"source": "/blog-old/**", "destination": "/blog-new/**", "type": 301}
  ],
  "rewrites": [
    {"source": "/blog-new/**", "destination": "/blog/index.html"}
  ]
}
B
{
  "rewrites": [
    {"source": "/blog-old/**", "destination": "/blog-new/**"},
    {"source": "/blog-new/**", "destination": "/blog/index.html"}
  ]
}
C
{
  "redirects": [
    {"source": "/blog-old/**", "destination": "/blog/index.html", "type": 301}
  ],
  "rewrites": [
    {"source": "/blog-new/**", "destination": "/blog/index.html"}
  ]
}
D
{
  "redirects": [
    {"source": "/blog-old/**", "destination": "/blog-new/**", "type": 302}
  ],
  "rewrites": [
    {"source": "/blog-new/**", "destination": "/blog/index.html"}
  ]
}
Attempts:
2 left
💡 Hint

Redirects change the URL in the browser; rewrites serve files without changing the URL.

security
advanced
3:00remaining
Security Implications of Firebase Hosting Redirects

Which Firebase Hosting redirect configuration could cause an open redirect vulnerability?

{
  "redirects": [
    {
      "source": "/goto",
      "destination": "https://example.com",
      "type": 302
    }
  ]
}
ARedirecting to an external URL based on user input without validation can cause open redirect vulnerabilities.
BUsing a 302 redirect always prevents open redirect vulnerabilities.
CRedirecting only within the same domain can cause open redirect vulnerabilities.
DRedirecting to a fixed external URL like https://example.com is safe and does not cause open redirect issues.
Attempts:
2 left
💡 Hint

Think about what happens if the destination URL is dynamic and user-controlled.

Best Practice
expert
3:00remaining
Optimizing Firebase Hosting Rules for Performance

You have many redirect and rewrite rules in your Firebase Hosting config. Which practice improves performance and reduces rule conflicts?

AUse only redirects and avoid rewrites to simplify the config.
BPlace general wildcard rules before specific rules to catch all requests early.
CCombine all redirects and rewrites into a single rule to reduce file size.
DPlace more specific rules before general wildcard rules to ensure correct matching order.
Attempts:
2 left
💡 Hint

Order of rules affects which rule matches first.