November 2021
How-To Setup Redirects For A Next.js Site On Netlify
Set up a redirects section in the netlify.toml file with a [[redirects]] entry for each redirect, like:
[[redirects]]
from = "/old-path"
to = "/new-path"
status = 301
force = false
query = {path = ":path"} # apply this rule for /old-path?path=example
conditions = {Language = ["en","es"], Country = ["US"]}
[[redirects]]
from = "/news"
to = "/blog"Redirect and entire site with:
[[redirects]]
from = "/*"
to = "https://www.example.com/"
status = 301
force = trueOld Notes
To use a _redirects file, set one up in the root of your project then change your build line in package.json to:
"build": "next build && cp _redirects .next/",That puts the file in the right place at the end of the build process.
via: https://docs.netlify.com/routing/redirects/
which says: "Save a plain text file called _redirects without a file extension to the publish directory of your site." but doesn't tell you how to actually do it.
TODO: put in syntax
Note: saw this in the build page of netlify:
A _redirects file is present in the repository but is missing in the publish directory ".next".
That was before I pushed it in with that package.json update.
end of line