We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
/2.0.1/foo
/2_0/foo
1 parent 025deef commit d60ec78Copy full SHA for d60ec78
src/middleware.ts
@@ -0,0 +1,12 @@
1
+import { defineMiddleware } from "astro/middleware";
2
+
3
+export const onRequest = defineMiddleware((context, next) => {
4
5
+ // path uses a semver (2.0.1) instead of a directory name (2_0)
6
+ let parts = context.url.pathname.match(/\/(?<major>[0-9]+)\.(?<minor>[0-9])+\.[0-9]+\/(?<rest>.*)$/);
7
+ if (parts?.groups) {
8
+ return Response.redirect(new URL(`/${parts.groups['major']}_${parts.groups['minor']}/${parts.groups['rest']}`, context.url), 301);
9
+ }
10
11
+ return next();
12
+});
0 commit comments