---
title: "Redirects and rewrites"
description: "Manage traffic to your site by defining redirect or rewrite rules in a _redirects file or a netlify.toml file."
---

> For the complete documentation index for AI agents, see [llms.txt](https://docs.netlify.com/llms.txt). Markdown versions of any documentation page are available by appending `.md` to its docs.netlify.com URL.

You can configure redirect and rewrite rules for your Netlify site in two ways:

- Save a plain text file called `_redirects` without a file extension to the [publish directory](/build/configure-builds/overview#definitions) of your site. You can find [`_redirects` file syntax](/manage/routing/redirects/overview#syntax-for-the-_redirects-file) details below.
- Add one or more `redirects` tables to your [Netlify configuration file](/build/configure-builds/file-based-configuration#redirects). This method allows for more structured configuration and additional capabilities, as described in the [Netlify configuration file syntax](/manage/routing/redirects/overview#syntax-for-the-netlify-configuration-file) section below.

### Tip - Framework considerations

If your site uses a specific framework, there may be additional redirect options or caveats for you to consider. Learn more in our [framework](/build/frameworks/overview) docs.

Netlify processes and serializes your redirect rules across the `_redirects` and `netlify.toml` files. If the size of this output is too large, the deploy might fail.

If you need to set up 10,000 redirects or more, we recommend using [wildcards or placeholders](/manage/routing/redirects/redirect-options) as much as possible. For a more complex redirect setup, [Edge Functions](/build/edge-functions/overview) can be a better option.

## Syntax for the `_redirects` file

In a `_redirects` file, each redirect rule must be listed on a separate line, with the original path followed by the new path or URL. Any line beginning with `#` will be ignored as a comment. Paths are case-sensitive and special characters in paths must be url-encoded.

Here is an example:

```
# Redirects from what the browser requests to what we serve
/home                /
/blog/my-post.php    /blog/my-post
/news                /blog
/cuties              https://www.petsofnetlify.com
/authors/c%C3%A9line /authors/about-c%C3%A9line
```

You can customize and alter the redirect behavior by adding options to the end of each line such as HTTP status code, country conditions, or language conditions. Visit the [redirect options](/manage/routing/redirects/redirect-options) doc for more details on these and other configuration options including query parameters, [forced redirects with `!`](/manage/routing/redirects/redirect-options#force-redirects), domain-level redirects, and more. You can also use redirects for [rewrites and proxies](/manage/routing/redirects/rewrites-proxies).

### Caution - Make sure we can access the file

If you're running a build command or site generator, the `_redirects` file should end up in the folder you're deploying. Some generators, like Jekyll, may also require additional configuration to avoid exclusion of files that begin with `_`. (For Jekyll, this requires [adding an `include` parameter](https://jekyllrb.com/docs/configuration/options/) to `_config.yml`.)

## Syntax for the Netlify configuration file

If you specify your redirect rules in your [Netlify configuration file](/build/configure-builds/file-based-configuration#redirects), you can use a more structured configuration format with additional capabilities such as [signed proxy redirects](/manage/routing/redirects/rewrites-proxies#signed-proxy-redirects). In a `netlify.toml` file, we use [TOML's array of tables](https://toml.io/en/v1.0.0-rc.3#array-of-tables) to specify each individual redirect rule. The following keywords are available:

* `from`: The case-sensitive path you want to redirect. Special characters must be url-encoded.
* `to`: The URL or path you want to redirect to. Special characters must be url-encoded.
* `status`: The [HTTP status code](/manage/routing/redirects/redirect-options#http-status-codes) you want to use in that redirect; `301` by default.
* `force`: Whether to override any existing content in the path or not; `false` by default. Visit the [shadowing](/manage/routing/redirects/rewrites-proxies#shadowing) instructions for more details.
* `query`: Query string parameters REQUIRED to match the redirect. Visit the [query parameters](/manage/routing/redirects/redirect-options#query-parameters) instructions for more details.
* `conditions`: Conditions to match the redirect, including [country](/manage/routing/redirects/redirect-options#redirect-by-country-or-language), [role](/manage/routing/redirects/redirect-options#redirect-by-role), and [cookie presence](/manage/routing/redirects/redirect-options#redirect-by-cookie-presence) conditions.
* `headers`: Additional request headers to send in [proxy redirects](/manage/routing/redirects/rewrites-proxies#custom-headers-in-proxy-redirects).
* `signed`: Name of an environment variable for [signed proxy redirects](/manage/routing/redirects/rewrites-proxies#signed-proxy-redirects).

You can specify any number of rules in your `netlify.toml` following that format:

```toml
[[redirects]]
  from = "/old-path"
  to = "/new-path"
  status = 301
  force = false
  query = {path = ":path"}
  conditions = {Language = ["en"], Country = ["US"], Role = ["admin"]}

## This rule redirects to an external API, signing requests with a secret
[[redirects]]
  from = "/search"
  to = "https://api.mysearch.com"
  status = 200
  force = true # COMMENT: ensure that we always redirect
  headers = {X-From = "Netlify"}
  signed = "API_SIGNATURE_TOKEN"
```

Visit the [redirect options](/manage/routing/redirects/redirect-options) doc for more details on configuration options including placeholders, trailing slashes, and more. Check out the [rewrites and proxies](/manage/routing/redirects/rewrites-proxies) doc for details on rewrite-specific options.

## Rule processing order

The redirects engine will process the first matching rule it finds, reading from top to bottom. Rules in the `_redirects` file are always processed first, followed by rules in the Netlify configuration file.

The following example uses `_redirects` file syntax:

```
# This rule will trigger at /blog/my-old-title
/blog/my-old-title   /blog/my-new-title

# This rule will never trigger because the previous rule triggers first
/blog/my-old-title   /blog/an-even-better-title
```

Note that for each request, Netlify processes [edge functions](/build/edge-functions/overview) before redirects. For more information, visit our docs about the [edge function declaration processing order](/build/edge-functions/declarations#declaration-processing-order).
