Skip to content

Commit ccf13c6

Browse files
committed
Maybe?
1 parent 264c453 commit ccf13c6

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

src/middleware.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,12 @@ import type { MiddlewareHandler } from 'astro';
33
/**
44
* This middleware converts the pathname to lowercase and adds .html to the final path for documentation pages and redirects the request to the URL with a 301 status code.
55
*/
6-
export const onRequest: MiddlewareHandler = async ({ request }, next) => {
7-
const url = new URL(request.url);
6+
export const onRequest: MiddlewareHandler = async (context, next) => {
7+
const url = new URL(context.request.url);
88

99
if (url.pathname.includes('wiki/') && !url.pathname.includes('.html')) {
1010
const redirectUrl = `${url.pathname.toLocaleLowerCase()}.html`;
11-
return new Response(null, {
12-
status: 301,
13-
headers: {
14-
Location: redirectUrl,
15-
},
16-
});
11+
return context.rewrite(new Request(new URL(redirectUrl, url.origin)));
1712
}
1813

1914
return next();

0 commit comments

Comments
 (0)