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

Middleware x Rewriting url without locale prefix returns 404 #32991

Closed
youminkim opened this issue Jan 4, 2022 · 3 comments
Closed

Middleware x Rewriting url without locale prefix returns 404 #32991

youminkim opened this issue Jan 4, 2022 · 3 comments
Labels
bug Issue was opened via the bug report template.

Comments

@youminkim
Copy link

Run next info (available from version 12.0.8 and up)

No response

What version of Next.js are you using?

12.0.7

What version of Node.js are you using?

v14.15.4

What browser are you using?

chrome

What operating system are you using?

macOS

How are you deploying your application?

vercel

Describe the Bug

While rewriting subdomain in middleware, page is not loaded based on locale prefix.

import { NextResponse } from 'next/server';

export function middleware(req, ev) {
    ...

    // rewrite
    if (
        !pathname.includes('.') && // exclude all files in the public folder
        !pathname.startsWith('/api') // exclude all API routes
    ) {
        return NextResponse.rewrite(`/a/${subdomain}`); // return 404 not found
    }

    return response;
}

I tried return NextResponse.rewrite("/en/a/support") instead. In this case, the first hit returns white screen. second hit returns proper page.

Note that /a/support page use getStaticProps and getStaticPaths with fallback=true.

Sharing next.config.js

const moduleExports = {
    ...
    i18n: {
        locales: ['en', 'id', 'es'],
        defaultLocale: 'en'
    }
    ...
}

Expected Behavior

return NextResponse.rewrite(/en/a/${subdomain}) should work

To Reproduce

i18n setting in next.config.js

prepare ISR page

In middleware, rewrite without locale preifx. e.g. return NextResponse.rewrite(/a/abc)

@youminkim youminkim added the bug Issue was opened via the bug report template. label Jan 4, 2022
@balazsorban44
Copy link
Member

This might have already been fixed in #31174. Could you verify by using npm i next@canary

@youminkim
Copy link
Author

Thanks @balazsorban44
it works well after upgrading

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Feb 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

No branches or pull requests

2 participants