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
}
]
}
}Think about what a 301 redirect means in web hosting.
A 301 redirect tells browsers and search engines that the page has permanently moved to a new URL. So visiting /old-page sends the user to /new-page and updates the URL in the browser.
Consider this Firebase Hosting rewrite rule:
{
"hosting": {
"rewrites": [
{
"source": "/app/**",
"destination": "/index.html"
}
]
}
}What happens when a user visits /app/profile?
Rewrite rules serve a file without changing the URL in the browser.
Rewrite rules serve the specified destination file for matching URLs but keep the original URL in the browser. So /app/profile serves /index.html content without URL change.
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?
Redirects change the URL in the browser; rewrites serve files without changing the URL.
Option A correctly uses a 301 redirect to permanently send /blog-old/** requests to /blog-new/** URLs, then rewrites /blog-new/** requests to serve /blog/index.html content without changing the URL.
Which Firebase Hosting redirect configuration could cause an open redirect vulnerability?
{
"redirects": [
{
"source": "/goto",
"destination": "https://example.com",
"type": 302
}
]
}Think about what happens if the destination URL is dynamic and user-controlled.
Open redirect vulnerabilities happen when attackers can control the redirect destination, leading users to malicious sites. Fixed redirects like in the example are safe, but dynamic redirects without validation are risky.
You have many redirect and rewrite rules in your Firebase Hosting config. Which practice improves performance and reduces rule conflicts?
Order of rules affects which rule matches first.
Firebase Hosting processes rules top to bottom. Specific rules should come first to match exact paths before general wildcards catch everything else. This avoids conflicts and improves performance.