Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i18n routing with rewrite on /[defaultLocale] next.config.js + middleware cased redirect loop #40678

Open
1 task done
williamli opened this issue Sep 19, 2022 · 1 comment
Labels
bug Issue was opened via the bug report template. stale The issue has not seen recent activity.

Comments

@williamli
Copy link
Contributor

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

npx --no-install next info [80%]

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 21.6.0: Mon Aug 22 20:19:52 PDT 2022; root:xnu-8020.140.49~2/RELEASE_ARM64_T6000
Binaries:
  Node: 16.17.0
  npm: 8.19.1
  Yarn: 1.22.19
  pnpm: N/A
Relevant packages:
  next: 12.3.0
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Describe the Bug

Reproduction: https://github.com/vercel-support/93483-mre

next.config.js:

module.exports = {
  i18n: {
    defaultLocale: 'default',
    localeDetection: false,
    locales: ['default', 'en-gb', 'en-ca'],
  },
  async rewrites() {
    return [
      {
        destination: '/en-gb/nextjs.org',
        source: '/default',
        locale: false,
      },
      {
        destination: '/en-ca/nextjs.org',
        source: '/en-ca',
        locale: false,
      },
    ];
  },
};

middleware.js:

import { NextResponse } from 'next/server';

export function middleware() {
  return NextResponse.next();
}

When you visit /, you will enter a redirect loop.

If middleware.js or the rewrite on /default is removed, then there will not be a redirect loop.

Expected Behavior

Request for / should not result in a redirect loop.

Link to reproduction

https://github.com/vercel-support/93483-mre

To Reproduce

Reproduction: https://github.com/vercel-support/93483-mre

next.config.js:

module.exports = {
  i18n: {
    defaultLocale: 'default',
    localeDetection: false,
    locales: ['default', 'en-gb', 'en-ca'],
  },
  async rewrites() {
    return [
      {
        destination: '/en-gb/nextjs.org',
        source: '/default',
        locale: false,
      },
      {
        destination: '/en-ca/nextjs.org',
        source: '/en-ca',
        locale: false,
      },
    ];
  },
};

middleware.js:

import { NextResponse } from 'next/server';

export function middleware() {
  return NextResponse.next();
}

When you visit /, you will enter a redirect loop.

@williamli williamli added the bug Issue was opened via the bug report template. label Sep 19, 2022
@vercel-release-bot
Copy link
Collaborator

This issue has been automatically marked as stale due to two years of inactivity. It will be closed in 7 days unless there’s further input. If you believe this issue is still relevant, please leave a comment or provide updated details. Thank you.

@vercel-release-bot vercel-release-bot added the stale The issue has not seen recent activity. label Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. stale The issue has not seen recent activity.
Projects
None yet
Development

No branches or pull requests

2 participants