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>
3
3
< p > Error 404: The page you are looking for does not exist.</ p >
4
4
</ div >
5
5
< 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
9
7
const path = window . location . pathname ;
10
8
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 ) {
13
17
window . location . replace ( newPath ) ;
14
18
} else {
19
+ // Show the 'not-found' element if no redirect is needed
15
20
document . getElementById ( 'not-found' ) . style . display = 'block' ;
16
21
}
17
22
</ script >
You can’t perform that action at this time.
0 commit comments