Skip to content

Commit cbbb51d

Browse files
committed
Fix infinite redirect
1 parent 2890b40 commit cbbb51d

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/middleware.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ import type { MiddlewareHandler } from 'astro';
55
*/
66
export const onRequest: MiddlewareHandler = async ({ request }, next) => {
77
const url = new URL(request.url);
8+
89
if (url.pathname.includes('/wiki')) {
910
const normalizedPath = url.pathname.toLowerCase().replace(/\/$/, '');
1011

1112
if (url.pathname !== normalizedPath) {
12-
url.pathname = normalizedPath;
13-
return Response.redirect(url.toString(), 301);
13+
const redirectUrl = `${url.origin}${normalizedPath}${url.search}`;
14+
return Response.redirect(redirectUrl, 301);
1415
}
1516
}
1617

0 commit comments

Comments
 (0)