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

Accessing Non-Existent Pages Does Not Return HTTP 404 Status Code #425

Open
shunshimono opened this issue Sep 26, 2024 · 1 comment
Open
Labels
bug Something isn't working

Comments

@shunshimono
Copy link

shunshimono commented Sep 26, 2024

Describe the bug
Accessing a non-existent page does notreturn an HTTP 404 status code. Instead, it returns a 200 status code, which can lead to issues with SEO and proper error handling.

To Reproduce

  1. Set up a Next.js project using next-international.(Custom 404 Page set)
  2. Start the development server.
  3. Navigate to a URL that does not correspond to any existing page or route (e.g., http://localhost:3000/non-existent-page).
  4. Observe that the page loads without displaying a 404 error, and the HTTP status code is 200.
app
├── [local]
  └── not-found.tsx
  └── [...other]
        └── page.tsx

[...other]/page.tsx

import { notFound } from 'next/navigation';

export default function CatchAllPage() {
  notFound();
}

middleware.ts

import type { NextRequest } from 'next/server';
import { createI18nMiddleware } from 'next-international/middleware';

const I18nMiddleware = createI18nMiddleware({
  locales: ['ja', 'en'],
  defaultLocale: 'ja',
  urlMappingStrategy: 'rewriteDefault',
});

export function middleware(request: NextRequest) {
  return I18nMiddleware(request);
}

export const config = {
  matcher: ['/((?!api|static|.*\\..*|_next|favicon.ico|robots.txt).*)'],
};

Expected behavior
The application should return an HTTP 404 status code when a user accesses a non-existent page, displaying a 404 error page accordingly.

Screenshots
N/A

About (please complete the following information):

  • next-international version [1.2.3]
  • Next.js version [14.2.0]

Additional context
This issue affects error handling and SEO, as search engines might index non-existent pages due to the incorrect status code

@shunshimono shunshimono added the bug Something isn't working label Sep 26, 2024
@MemoS77
Copy link

MemoS77 commented Oct 3, 2024

Same problem. No 404 code. Always 200...

import { createI18nMiddleware } from 'next-international/middleware'
import { NextRequest, NextResponse } from 'next/server'

export const defaultLocale = 'en'

const I18nMiddleware = createI18nMiddleware({
  locales: ['en', 'ru'],
  defaultLocale,  
})

export function middleware(request: NextRequest) {
return I18nMiddleware(request)
}

export const config = {
  matcher: ['/((?!api|static|.*\\..*|_next).*)'],
}

Screenshot_103

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants