Skip to content

Commit 5df8a41

Browse files
committed
fix: handle trailing slashes correctly in markdown redirects
1 parent a2fecde commit 5df8a41

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/middleware.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,10 @@ const handleAIClientRedirect = (request: NextRequest) => {
7979
// Create new URL with .md extension
8080
const newUrl = url.clone();
8181
// Handle root path and ensure proper .md extension
82-
const pathname = url.pathname === '/' ? '/index' : url.pathname.replace(/\/$/, '');
83-
newUrl.pathname = pathname + '.md';
82+
let pathname = url.pathname === '/' ? '/index' : url.pathname;
83+
// Remove trailing slash if present, then add .md
84+
pathname = pathname.replace(/\/$/, '') + '.md';
85+
newUrl.pathname = pathname;
8486

8587
// Clean up the format query parameter if it was used
8688
if (forceMarkdown) {

0 commit comments

Comments
 (0)