Skip to content

Commit

Permalink
Preserve the path when redirecting the latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
peterguy committed Jan 24, 2025
1 parent a95d95b commit a0aad14
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ export function middleware(request: NextRequest) {
if (pathWithoutBase.startsWith(`/v/${docsConfig.DOCS_LATEST_VERSION}/`)) {
return NextResponse.redirect(createRedirectUrl(
request,
`https://sourcegraph.com/docs/:slug*`,
pathWithoutBase
pathWithoutBase.substring(`/v/${docsConfig.DOCS_LATEST_VERSION}/`.length - 1),
""
))
}
if (pathWithoutBase.startsWith(`/@${docsConfig.DOCS_LATEST_VERSION}/`)) {
return NextResponse.redirect(createRedirectUrl(
request,
`https://sourcegraph.com/docs/:slug*`,
pathWithoutBase
pathWithoutBase.substring(`/@${docsConfig.DOCS_LATEST_VERSION}/`.length - 1),
""
))
}
const versionMatch = pathWithoutBase.match(/^\/v\/(\d+\.\d+)\/(.*)/)
Expand Down

0 comments on commit a0aad14

Please sign in to comment.