Skip to content

Next.js Rewrites and Redirects Error Fix

DodaTech Updated 2026-06-24 1 min read

In this tutorial, you'll learn about Next.js Rewrites and Redirects Error Fix. We cover key concepts, practical examples, and best practices.

The Problem

Error: Invalid redirect configuration. "destination" is required.

The redirects function returns an object missing the required destination or source fields.

Wrong

// next.config.js
module.exports = {
  async redirects() {
    return [
      {
        source: '/old-page',
        // missing destination
      },
    ]
  },
}

Output: Error: Invalid redirect configuration. when Next.js validates the config.

module.exports = {
  async redirects() {
    return [
      {
        source: '/old-page',
        destination: '/new-page',
        permanent: true, // 308 redirect
      },
    ]
  },
  async rewrites() {
    return [
      {
        source: '/api/:path*',
        destination: 'https://api.example.com/:path*',
      },
    ]
  },
}

Expected output: /old-page redirects to /new-page with 308 status.

Prevention

  • Always include source, destination, and either permanent or statusCode
  • Test redirects on local dev server before deploying
  • Use permanent: true for SEO-friendly 308 redirects

Common Mistakes with rewrites redirects

  1. Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable
  2. Using head and tail instead of pattern matching, causing runtime errors on empty lists
  3. Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks

These mistakes appear frequently in real-world NEXTJS code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### What is the difference between rewrites and redirects in Next.js?

Rewrites are proxied (URL stays the same in the browser, content comes from another URL). Redirects change the browser URL to a new destination (301/302/307/308).

Can I use wildcards in redirect sources?

Yes. Use :path* for catch-all segments: source: '/blog/:slug*'. Wildcards are replaced by values from the source URL.

How do I test redirects locally?

Redirections work in next dev. Navigate to the source URL and check the browser URL bar for the redirected destination. Check the Network tab for the redirect status code.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro