File tree Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -3,15 +3,20 @@ <h1>Page not found</h1>
33 < p > Error 404: The page you are looking for does not exist.</ p >
44</ div >
55< script >
6- // Did we land on a page that doesn't exist
7- // that starts with a uppercase letter?
8- // Send to a path with the first letter lowercase
6+ // Get the current path
97 const path = window . location . pathname ;
108
11- if ( path . length > 1 && / [ A - Z ] / . test ( path [ 1 ] ) ) {
12- const newPath = path [ 0 ] + path [ 1 ] . toLowerCase ( ) + path . slice ( 2 ) ;
9+ // Transform the path: lowercase the first letter of each segment
10+ const newPath = path
11+ . split ( '/' )
12+ . map ( segment => segment ? segment [ 0 ] . toLowerCase ( ) + segment . slice ( 1 ) : '' )
13+ . join ( '/' ) ;
14+
15+ // Redirect only if the transformed path is different from the current path
16+ if ( newPath !== path ) {
1317 window . location . replace ( newPath ) ;
1418 } else {
19+ // Show the 'not-found' element if no redirect is needed
1520 document . getElementById ( 'not-found' ) . style . display = 'block' ;
1621 }
1722</ script >
You can’t perform that action at this time.
0 commit comments