How do I add redirects with Netlify's _redirects file?

The Citead team, updated

In short. Place a plain text _redirects file in the publish directory, with one source and destination per line and an optional status code that defaults to 301.

Definition: As of October 2026, Netlify's _redirects file is a plain text file in a site's publish directory that maps requested paths to destination paths or URLs. Each line contains a rule, with an optional HTTP status code that controls the response.

Key facts

  • Netlify's redirects overview requires the filename _redirects without a file extension in the publish directory.
  • Netlify's redirect options documentation specifies 301 as the default status and 302 for a temporary redirect.
  • Netlify's rewrites documentation explains that a rule with status 200 serves another location while keeping the visitor's address bar unchanged.

Where does the file go, and what does a rule contain?

The publish directory is the folder of finished files that Netlify deploys after the build command runs. Netlify's file syntax documentation requires _redirects to reach that deployed folder when a build command or site generator is involved.

Each rule occupies a separate line: the original path comes first, followed by the destination path or URL. A line beginning with # is a comment. The following rules use paths and destinations from the documentation:

# Original path followed by destination
/home                /
/blog/my-post.php    /blog/my-post
/news                /blog
/cuties              https://www.petsofnetlify.com

/ is the site's root destination; the last rule uses a complete external URL. Paths are case-sensitive, and special characters require URL encoding. The same documentation gives /authors/c%C3%A9line as an encoded source path.

Which status code belongs at the end?

An HTTP status code describes the server's response to a browser or other client. Netlify's status code reference gives these examples:

/home          /              301
/my-redirect   /              302
/ecommerce     /store-closed   404
/pass-through  /index.html    200

301 indicates a permanent move and changes the browser's displayed address. Omitting the status selects this default. 302 indicates a temporary move and also changes the displayed address; Netlify documents 307 as unsupported.

404 serves custom missing-page content at the requested address. A rewrite serves content from another location while preserving the requested address; status 200 selects that behavior. For example, /pass-through serves /index.html through the rewrite shown above.

How do destination patterns and rule order work?

A splat is a wildcard that captures everything following an asterisk. Netlify's splat documentation uses :splat to insert that captured text into a destination:

/news/*  /blog/:splat

This preserves the part after /news/ under /blog/. The asterisk belongs at the end of the source pattern; Netlify excludes patterns such as /jobs/*.html.

Netlify's rule processing documentation specifies that the first matching rule wins, reading from top to bottom. Specific paths therefore precede broader wildcard rules. Rules in _redirects are processed before rules in netlify.toml, Netlify's structured configuration file.

FAQ

Why does my rule leave an existing file visible?

Netlify's force redirect documentation explains that a matching file can prevent a redirect. You can append ! to the status code to force the rule, as in its example:

/best-pets/dogs  /best-pets/cats.html 200!

Can I use a rule to remove a trailing slash?

Netlify's redirect options documentation states that paths match regardless of their trailing slash, so you cannot use a redirect rule to add or remove it. Its documented alternative is the Pretty URLs feature.

Do I need a status code on every line?

You can omit the status code when you intend a permanent 301 redirect. Netlify's redirect options documentation specifies that default; an explicit 302 selects a temporary redirect.

Sources

  1. Netlify, "Redirect options", 17 September 2026
  2. Netlify, "Redirects and rewrites", 14 July 2025
  3. Netlify, "Rewrites and proxies", 14 July 2025

Check how a page reads to answer engines. Open the GEO score analyzer

Test a page and see what to fix first

The analysis usually takes less than 10 seconds and needs no account.

400,000+ pages scored in the public benchmark