Skip to content

Commit ad78443

Browse files
Apply path first letter lowercase to all segments
1 parent 210b92b commit ad78443

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

web/resources/404.html

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff 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>

0 commit comments

Comments
 (0)