How to setup a permanent redirect with Nuxt and Netlify

Nuxt guide logo

Nuxt permanent redirection with Netlify configuration.

Create a _redirects file in the root of the Nuxt project.

And write the code below in _redirects file.

/news/* https://www.yournewdomain.com/news/:splat 301!

You can also add multiple line.

/news/* https://www.newdomain.com/news/:splat 301!

/blog/* https://www.newdomain.com/blog/:splat 301!

This will redirect all of the articles under https://www.olddomain.com/news/ to https://www.newdomain.com/news/ and https://www.olddomain.com/blog/ to https://www.newdomain.com/blog/.

Build Command

Now we need to setup a build command so the _redirects file is copy over to the build folder. In Netlify UI Dashboard or in Netlify config file change the build command to (assuming the publish folder name is dist)

yarn build && cp _redirects dist/_redirects

Or if it's SSG (statically generated file & assuming the publish folder name is dist)

yarn generate && cp _redirects dist/_redirects

Previous post How to mutating prop in Nuxt or Vuejs
Next post How to get route url params in Nuxt