404 renders EN version of the page even when on NL website

Hello,

We are having problems with returning 404 page in correct language on the NextJS website with enabled internationalization. The website is deployed via SSG and has a custom 404 page.

Direct link to 404 page:
https://develop--biobest.netlify.app/nl/404 → gives back generated 404 page in correct language (NL): Page not found [nl]
https://develop--biobest.netlify.app/404 → gives back generated 404 page in correct language (default=EN): Page not found.

However, when requesting really non-existing page, the problem appears:
https://develop--biobest.netlify.app/nl/this-page-really-doesnt-exist
expected: 404 page in NL
actual: 404 page in EN

Could you please have a look into it? How can we fix it?

I have also checked at the redirects deployed with the website and found there these rules in the deploy log:

<skipped logs>
2:45:45 PM:   { from: '/', to: '/en/404.html', status: 404, force: false },
2:45:45 PM:   { from: '/*', to: '/en/404.html', status: 404, force: false },
<skipped logs>
2:45:45 PM:   { from: '/nl', to: '/nl/404.html', status: 404, force: false },
2:45:45 PM:   { from: '/nl/*', to: '/nl/404.html', status: 404, force: false },
<skipped logs>

My assumption would be that the order of these redirects is inverted → when /nl/non-existing is requested, the top rule redirects to /en/404. While instead, the order should be swapped, so that /nl/* is processed before /*

Is there a workaround for this?

Kind regards,
Max

The Next.js Runtime should be able to preserve the order of your redirects. How are you defining the redirects in your configuration?

Thanks for the answer. I don’t define any specific redirects for the Nextjs, I thought Netlify-nextjs runtime should do it automatically. I can try defining it however, maybe it will help…

Hi,

I have tried to define the rewrites in next.config.js file as such:

 async rewrites() {
    return {
      fallback: [
        {
          source: '/nl/(.*)',
          destination: '/nl/404',
          locale: false,
        },
        {
          source: '/(.*)',
          destination: '/404',
          locale: false,
        },
      ],
    };

however it doesn’t help. I still see the redirects in the logs are in wrong order, same as in the topic.
Just make it more clear, the redirects I’ve mentioned in the topic are the ones created automatically the netlify-nextjs plugin. I haven’t added them. When I run the website in pnpm dev it works fine, however when deploying to Netlify it doesn’t. Seems like an issue in netlify nextjs plugin.

What would be further steps to mitigate that?

Kind regards,
MAx

Hey Netlify, any update on this case?

Hey @max.may ,

I’ve replied in your helpdesk ticket :slight_smile: