opennextjs / opennextjs-aws

Open-source Next.js adapter for AWS
https://opennext.js.org
MIT License
4.14k stars 126 forks source link

External redirects issues without trailing slash #591

Closed iDVB closed 2 weeks ago

iDVB commented 3 weeks ago

What settings do I need to use in NextJS to redirect ALL 'source/path' from a host/domain to forward to the index/homepage of another domain.

this WORKS:

      {
        source: '/(.*)',
        destination: 'https://primary.domain.com',
        permanent: false,
        locale: false,
        has: [
          {
            type: 'header',
            key: 'x-forwarded-host',
            value: 'other.com',
          },
        ],
      },

this does NOT work:

      {
        source: '/:path*',
        destination: 'https://primary.domain.com',
        permanent: false,
        locale: false,
        has: [
          {
            type: 'header',
            key: 'x-forwarded-host',
            value: 'other.com',
          },
        ],
      },

it outputs location: https://primary.domain.com/undefined as response headers

BUT if you just put a trailing slash at the end ... then that WORKS....

      {
        source: '/:path*',
        destination: 'https://primary.domain.com/',
        permanent: false,
        locale: false,
        has: [
          {
            type: 'header',
            key: 'x-forwarded-host',
            value: 'other.com',
          },
        ],
      },

https://discord.com/channels/983865673656705025/1298382310831554560/1298662265037262930