1

I simply followed the doc by adding this to my next.config.js

module.exports = {
 reactStrictMode: true,
 async redirects() {
 return [
 {
 source: "/",
 destination: "/coming-soon",
 permanent: false,
 },
 ];
 },
}

It does work on my machin even when I build the app but on netlify there is no redirect at all for some reason

asked Nov 24, 2021 at 14:21
1

2 Answers 2

5

According to the official Netlify docs:

Redirects and rewrites using next.config.js aren't currently supported for Next.js sites on Netlify. If you have these specified in a next.config.js file for your project, check out our redirects and rewrites docs to learn how to set them up in a _redirects or netlify.toml file instead.

So you basically need to create a _redirects file at the top level of your project with the following contents:

/ /coming-soon 302

The 302 status code is equivalent to permanent: false that you've done in your config.

If you have a netlify.toml, then you can add something like this to make your stuff work:

[[redirects]]
 from = "/"
 to = "/coming-soon"
 status = 302
 force = false

References:

answered Nov 24, 2021 at 19:04
Sign up to request clarification or add additional context in comments.

1 Comment

It's best to use status code 301 as Netlify examples suggest. If you want to automate the process, I've written a little CLI script: npmjs.com/package/nextjs-to-netlify-redirect-exporter
-1

When we deploy a Next.js project on Netlify it automatically gets all the necessary dependencies including the Essential Next.js plugin (If it is not installed in the plugin tab, we have to install it manually). This plugin configures your Netlify site to allow essential Next.js capabilities. Version 4 of the Essential Next.js plugin adds support for native Next.js rewrites and redirects.

Basically, you can use native Next.js redirects/rewrites (configured in next.config.js) in Netlify by installing the Essential Next.js plugin version 4 or higher to your Next.js site deployed in Netlify.

Refer this to learn more about using Next.js and Netlify redirects/rewrites rules.

answered Apr 30, 2022 at 16:32

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.