Skip to content

Support next.config.js redirects, rewrites, headers #150

Closed
@scopsy

Description

@scopsy

First of all, thank you for the amazing work with this package!

Currently when defining experimental rewrites in next.config.js they are not respected in netlify and throw 404 error from netlify. Any chance they can be supported?

example of the config file:

module.exports = {
  target: 'serverless',
  experimental: {
    redirects() {
      const redirects = [
        {
          // Redirect root link with trailing slash to non-trailing slash, avoids 404 - See https://github.com/vercel/next.js/discussions/10651#discussioncomment-8270
          source: '/:locale/',
          destination: '/:locale',
          permanent: process.env.NEXT_PUBLIC_APP_STAGE !== 'development', // Do not use permanent redirect locally to avoid browser caching when working on it
        },
        {
          // Redirect link with trailing slash to non-trailing slash (any depth), avoids 404 - See https://github.com/vercel/next.js/discussions/10651#discussioncomment-8270
          source: '/:locale/:path*/',
          destination: '/:locale/:path*',
          permanent: true
        },
      ];

      return redirects;
    },
    rewrites() {
      const rewrites = [
        {
          source: '/',
          destination: '/api/autoRedirectToLocalisedPage',
        },
        {
          source: `/:locale((?!${noRedirectBasePaths.join('|')})[^/]+)(.*)`,
          destination: '/api/autoRedirectToLocalisedPage',
        },
      ];

      return rewrites;
    },
  },
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixed in upcoming releaseThis bug is fixed in the neext major release of the pluginpriority: mediumrewrite candidatetype: featurecode contributing to the implementation of a feature and/or user facing functionality

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions