Deployment on Netlify: Redirects and Routing Behavior for a Multi-Page Static Site
Overview
This section explains how Nexora Web Agency’s multi-page static site is routed and redirected by Netlify. Instead of a single-page application (SPA) model, the site relies on file-based routing—each .html file in dist/ corresponds directly to a URL path. Netlify pretty-URL handling removes the need for “.html” suffixes, and a custom 404 page provides a graceful fallback for unknown routes.
Two key redirect rules in netlify.toml control this behavior:
- An SPA-style catch-all redirect (
/*→/index.htmlwith status 200), which is not appropriate for a multi-page site. - A global 404 fallback (
/*→/404.htmlwith status 404) for unmatched paths.
Redirect Rules in netlify.toml
# ----------------------------------------------------
# Routing & Redirects
# ----------------------------------------------------
[[redirects]]
# Ensure clean URLs (explicit SPA fallback — remove for static HTML)
from = "/*"
to = "/index.html"
status = 200
[[redirects]]
# Global 404 fallback page
from = "/*"
to = "/404.html"
status = 404
SPA-Style Fallback Rule (/* → /index.html, status 200)
- Purpose: Serve
index.htmlfor every path (SPA behavior). - Implication: Hijacks all routes—valid
.htmlpages and non-existent paths alike. - Impact: Users navigating to
/aboutor/servicessee the homepage instead of the intended page, and genuine 404s are obscured. - Recommendation: Remove this rule for a multi-page static site to restore file-based routing and 404 handling.
Global 404 Fallback (/* → /404.html, status 404)
- Purpose: After all other rules (and absent an explicit file match), serve
404.htmlwith a 404 status. - Behavior: Any URL not mapping to a file in
dist/returns the custom 404 page. - Benefit: Provides clear feedback to users and search engines on missing pages.
Routing Flow
flowchart LR
A[User Request Path] --> B{File exists in dist folder?}
B -->|Yes| C[Serve corresponding .html file]
B -->|No| D[Evaluate redirect rules]
D -->|First rule: /* → index-html (200)| E[Serve index.html (undesired)]
D -->|Second rule: /* → 404-html (404)| F[Serve 404.html]
- By removing the first (SPA) rule, the flow simplifies: unmatched paths go directly to the 404 fallback.
Practical Implications
- Pretty URLs
Netlify automatically serves /about as /about.html and /contact/ as /contact.html. No extension is required in links or user input.
- Valid Pages
With the SPA fallback removed, requests to any existing HTML file (/services.html, /projects.html, etc.) render correctly.
- Missing Pages
Requests to non-existent routes (/nonexistent) trigger the global 404 redirect, delivering 404.html with status 404.
- SEO & Analytics
Proper 404 status codes improve search-engine indexing and allow analytics tools to differentiate between real content and missing pages.
Removing the SPA Fallback
The project’s README explicitly calls out the removal of the SPA redirect for multi-page sites:
“Remove SPA Redirect Rule: In netlify.toml, the rule from = "/*" to = "/index.html" status = 200 is designed for Single Page Applications (React/Vue). Because this is a multi-page static site, this rule can hijack legitimate 404s. It should be removed, relying solely on the defined 404 fallback.”
After removal, netlify.toml should only contain the 404 fallback under [[redirects]], ensuring clean, predictable routing.
Key Configuration Excerpt
# Publish directory and build command are defined above…
# Only the 404 fallback remains for multi-page routing:
[[redirects]]
from = "/*"
to = "/404.html"
status = 404
With this configuration, Nexora’s multi-page site will:
- Serve each page by filename without needing “.html” in URLs.
- Return the custom 404 page for any unknown path.
- Avoid unintended SPA behavior that could confuse users or search engines.