Configuration
Redirects, rewrites and SPA routing with _redirects
Everything you can do with a _redirects file on StaticHero: moved pages, splats, placeholders, rewrites, forced rules and custom 404s.
The StaticHero Team · · 1 min read
A _redirects file at the root of your upload controls how URLs are handled. Each line is a rule: from, to, and an optional status code.
Moved pages
/old-page /new-page 301
/2024/pricing /pricing 301Use 301 for permanent moves (search engines update their index) and 302 for temporary ones.
Splats
* matches everything after a prefix, available as :splat:
/blog/* /posts/:splat 301Placeholders
Name a path segment and reuse it:
/docs/:section/:page /guide/:section/:page 301Rewrites (status 200)
A 200 rule serves a different file without changing the URL — the basis of single-page apps:
/app/* /app/index.html 200
/* /index.html 200Forced rules
Normally, if a file exists at the requested path it’s served and the rule is skipped. Add ! to apply the rule anyway:
/index.html / 301!Custom 404 page
Add a 404.html at the root and it’s used for missing pages with a proper 404 status. You can also send specific paths to it:
/private/* /404.html 404Order matters
Rules are checked top to bottom and the first match wins, so put specific rules before general ones like /*.
Headers too
A _headers file sets response headers per path:
/assets/*
Cache-Control: public, max-age=31536000, immutable
/embed/*
Access-Control-Allow-Origin: *Keep reading
Your site could be live in the next minute.
One site free, forever. No credit card, no setup, no servers.