forked from ethereum/ethereum-org-website
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmiddleware.ts
More file actions
30 lines (24 loc) · 896 Bytes
/
middleware.ts
File metadata and controls
30 lines (24 loc) · 896 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { NextRequest, NextResponse } from "next/server"
import createMiddleware from "next-intl/middleware"
import { routing } from "./src/i18n/routing"
import { DEFAULT_LOCALE } from "./src/lib/constants"
const handleI18nRouting = createMiddleware(routing)
export default function middleware(request: NextRequest) {
const response = handleI18nRouting(request)
// Upgrade default-locale strip redirects from 307 to 301 for SEO
if (response.status === 307) {
const pathname = request.nextUrl.pathname
const defaultPrefix = `/${DEFAULT_LOCALE}`
if (
pathname === defaultPrefix ||
pathname.startsWith(`${defaultPrefix}/`)
) {
return new NextResponse(null, { status: 301, headers: response.headers })
}
}
return response
}
// Simplified matcher pattern
export const config = {
matcher: ["/((?!api|_next|_vercel|.well-known|.*\\.[^/]*$).*)"],
}