Redirects and rewrites (_redirects)
A _redirects file in your site tells the network what to do with addresses that have moved, or that don’t match a file. It uses the same format as Netlify and Cloudflare Pages, so a file you already have usually works unchanged. Moving from Netlify with a netlify.toml? ee-migrate writes this file from it.
It applies to Level 0 (public) sites only. See Scope and limits.
Where the file goes
Section titled “Where the file goes”Put _redirects in the root of your build output, next to your home page’s index.html. Most generators copy a static folder into the output unchanged, so put the file there:
| Generator | Put _redirects in |
|---|---|
| Astro, Vite, Qwik City | public/ |
| VitePress | docs/public/ (your source folder’s public/) |
| Hugo, Docusaurus, Gatsby | static/ |
| Eleventy | Any folder you pass through to the output |
| Jekyll | The site root, with include: [_redirects] in _config.yml |
The file travels with your site. It deploys and rolls back with the content it belongs to.
Syntax
Section titled “Syntax”One rule per line: the address to match, where to send it, and an optional status.
# Lines that start with # are comments/old-page /new-page/ 301/blog/* /news/:splat 301/:year/:slug /posts/:slug 301/shop https://shop.example.com/ 302fromis a path on your site, starting with/. It can also be a full URL on one of your domains, to redirect that domain: see Redirect a whole domain.tois a path on your site, or a full URL on another site.- Status defaults to
301if you leave it out. *at the end offrommatches the rest of the path. Use:splatintoto carry it over.:namematches one path segment. Use the same:nameinto.
Statuses
Section titled “Statuses”| Status | What it does |
|---|---|
301 |
Permanent redirect. The visitor’s address bar changes. |
302 |
Temporary redirect. The visitor’s address bar changes. |
200 |
Rewrite. Serves the target’s content at the address that was asked for. The address bar doesn’t change. |
404 |
Serves the target’s content with a 404 status. Use it for a not-found page for one section. See Custom 404 pages. |
307 and 308 aren’t supported.
A rewrite (200) can only serve a file from your own site. It can’t point at another site.
Which rule wins
Section titled “Which rule wins”-
A real file wins over a rule. If your site has a file at the requested path, it’s served, and the rule is skipped. Add
!to the status to force the rule to apply anyway:/old /new/ 301! -
Rules for a whole domain (with a full URL as
from) are checked first, on requests to that domain. -
Exact rules (no
*or:name) are checked next. -
Pattern rules are checked in the order they appear in the file. The first match wins.
-
If two rules have the same
from, the first one is used.
The first point is what makes a single-page-app fallback work. This rule sends every unknown path to your app, but still serves your real scripts, styles and images:
/* /index.html 200A path counts as having a real file if the file exists at that path, or if an index.html exists in a folder of that name.
Routing settings
Section titled “Routing settings”Three optional lines turn on behaviour for the whole site. Each is written as a comment, so the file still works on other hosts.
Add a trailing slash
Section titled “Add a trailing slash”# ee:trailing-slash onMany generators write each page as a folder with an index.html inside: about/index.html, served at /about/. Without this line, /about (no slash) is a 404. With it, /about redirects to /about/.
It applies to any path whose last part has no dot and no trailing slash. Your own rules are checked first, so it never adds an extra step in front of a redirect you wrote.
With Astro, also set trailingSlash: 'always' and build: { format: 'directory' } in astro.config.mjs, so your site’s own links use the slash.
Clean URLs
Section titled “Clean URLs”# ee:clean-urls onSome generators write flat files (about.html) but link to /about. With this line, /about is served from about.html, and the address bar stays on /about.
Generators that need it: Quartz, Observable Framework, Hono’s SSG helper, vite-ssg, Silex, îles and Emanote by default, and VitePress, Rspress, VuePress and HonKit when their cleanUrls option is on.
- A real file still wins.
/LICENSEservesLICENSEeven ifLICENSE.htmlexists. about.htmlcounts as the page at/about. A rule of your own for/aboutonly applies if you force it with!.- With both settings on,
/aboutservesabout.htmlwhen it exists, and redirects to/about/only when it doesn’t. /about.htmlstill works as well. Your generator’s canonical tag tells search engines which address you prefer.
Markdown for agents
Section titled “Markdown for agents”# ee:markdown onIf your build writes a Markdown copy beside each page (cli.md beside cli/index.html), this line serves the copy from the page’s own address to requests that ask for text/markdown. Browsers still get the HTML. See Markdown for agents.
Redirect a whole domain
Section titled “Redirect a whole domain”When your site moves to a new domain, a rule with a full URL as from sends every address on the old domain to the same address on the new one:
https://old.example.com/* https://www.example.com/:splat 301!The rule only applies to requests for old.example.com. On your other domains, your site works as before.
To set it up:
- Add a deployment target for the old domain in the same project, and claim the domain as you would any other.
- Deploy the same build to both targets: the one for your new domain and the one for the old domain. From the command line, run
ee-deployonce with each--domain. - Deploy to both again whenever you change the rules. Each target serves the deploy it was last given.
If the old domain only redirects, it doesn’t need your whole site. Deploy a folder holding just the rule in _redirects and an index.html to the old domain once, and keep deploying your site to the new one as before. For a large site, that saves uploading it twice on every deploy. Redirect the root domain to www walks through it for a root domain.
Things to know:
-
Add
!. Without it, a page that exists on your site keeps loading on the old domain instead of moving. -
Write
https://. The network moves everyhttp://request tohttps://before any rule runs, so anhttp://rule on its own never applies. The deploy warns about one. A rule that only sends a domain fromhttp://tohttps://on the same domain isn’t needed. -
Redirects only. A rule for a domain can use
301or302. It can’t rewrite (200) or serve a404. -
Moving one page on the old domain works the same way, without the
*:https://old.example.com/about https://www.example.com/about-us/ 301! -
wwwto the bare domain:https://www.example.com/* https://example.com/:splat 301!, with both domains claimed and deployed. See Root domains. -
Rules for
*.netlify.appdon’t apply here. The deploy says so, and still goes ahead. You can remove them. -
The deploy lists the domains your rules name, for example
_redirects: domain-level rules for old.example.com; each fires only once that domain is claimed and bound to this site. A rule for a domain you haven’t claimed and deployed to does nothing.
Common recipes
Section titled “Common recipes”Move one page:
/pricing-2025 /pricing/ 301Move a whole section, keeping the rest of each address:
/blog/* /news/:splat 301Move to a new domain: see Redirect a whole domain.
https://old.example.com/* https://www.example.com/:splat 301!Send a section to another site:
/docs/* https://docs.example.com/:splat 301A single-page app, where every unknown path loads the app:
/* /index.html 200A not-found page for one section:
/docs/* /docs/404.html 404Scope and limits
Section titled “Scope and limits”-
Level 0 sites only. Encrypted sites (Level 1 and Level 2) don’t read
_redirects. See encryption levels. -
307and308aren’t supported. -
Rewrites stay on your site. A
200rule that points at another site is refused. -
Conditions aren’t supported. Netlify’s
Country=,Language=,Role=andCookie=conditions, and rules that match on query parameters, stop the deploy. -
Up to 2,000 rules per file.
-
Redirects are cached for 5 minutes by browsers, so a rule you remove stops applying soon after your next deploy.
-
The file isn’t downloadable. A request for
/_redirectsgets a 404. -
Some paths belong to the network and can’t be redirected or used for your own files:
- the files visitors’ browsers use to load your site:
/ee.js,/ee-worker.js,/brotli_wasm.wasm; - exactly
/healthand/discover; /_header,/_index,/_blocks,/_torrent,/_digestand anything under/_piece/;- anything under
/.ee/.
Paths such as
/health/team,/discover/productsand/ee/docs/are yours. - the files visitors’ browsers use to load your site:
Checking your file
Section titled “Checking your file”Your file is checked when you deploy, from the portal or the command line. The deploy stops, and names each line, if the file has:
- a rule with no target, or a target that isn’t a path or a full URL;
- a status other than
301,302,200or404; - a rule that redirects to itself, or a chain of rules that loops, including a domain rule that sends its domain back to itself, or two domains that redirect to each other;
- a rewrite (
200) or404rule whose target is on another site, or isn’t a file in your site; - a condition or a query-parameter match;
- a domain rule that rewrites (
200) or serves a404, or whosefromisn’t a plain domain (no port, IP address or*in the domain); - a rule for a path that belongs to the network;
- more than 2,000 rules.
Two rules with the same from only produce a warning, since the first one is used. So do an http:// domain rule without an https:// one, and a rule for a *.netlify.app address.
The deploy also prints what it found, for example _redirects: 3 rule(s), trailing-slash: on, clean-urls: off, markdown: off. Check that line if a routing setting doesn’t seem to apply: a tool that strips comments can remove the setting without any other sign.
To check a rule after deploying, request the old address and look at the status and Location:
curl -sI https://www.example.com/old-page