@@ -2,27 +2,39 @@ import type { NextRequest } from 'next/server';
22import { NextResponse } from 'next/server' ;
33
44export const config = {
5- matcher : '/_next/static/chunks/:path*' ,
5+ matcher : [ '/_next/static/chunks/:path*' , '/organizations/:slug/details' ] ,
66} ;
77
88export function middleware ( request : NextRequest ) {
99 const url = request . nextUrl . clone ( ) ;
10- const originalPathname = url . pathname ;
10+ const { pathname } = url ;
1111
12- const decodedPathParts = originalPathname . split ( '/' ) . map ( ( part ) => {
13- try {
14- return decodeURIComponent ( part ) ;
15- } catch {
16- return part ;
17- }
18- } ) ;
12+ // Handle organization details redirect
13+ const orgDetailsMatch = pathname . match ( / ^ \/ o r g a n i z a t i o n s \/ ( [ ^ / ] + ) \/ d e t a i l s $ / ) ;
14+ if ( orgDetailsMatch ) {
15+ const slug = orgDetailsMatch [ 1 ] ;
16+ const newUrl = new URL ( `/organizations/info/ ${ slug } ` , request . url ) ;
17+ return NextResponse . redirect ( newUrl , 308 ) ; // 308 Permanent Redirect
18+ }
1919
20- const decodedPathname = decodedPathParts . join ( '/' ) ;
20+ // Static chunk decoding check
21+ if ( pathname . startsWith ( '/_next/static/chunks/' ) ) {
22+ const originalPathname = pathname ;
23+ const decodedPathParts = originalPathname . split ( '/' ) . map ( ( part ) => {
24+ try {
25+ return decodeURIComponent ( part ) ;
26+ } catch {
27+ return part ;
28+ }
29+ } ) ;
30+ const decodedPathname = decodedPathParts . join ( '/' ) ;
2131
22- if ( decodedPathname === originalPathname ) {
23- return NextResponse . next ( ) ;
32+ if ( decodedPathname !== originalPathname ) {
33+ url . pathname = decodedPathname ;
34+ return NextResponse . rewrite ( url ) ;
35+ }
2436 }
2537
26- url . pathname = decodedPathname ;
27- return NextResponse . rewrite ( url ) ;
38+ // Allow other requests to pass through
39+ return NextResponse . next ( ) ;
2840}
0 commit comments