Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵月辉
/
fastgpt-migrated
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
45c9761d
authored
May 07, 2026
by
Archer
Committed by
GitHub
May 07, 2026
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
redirect (#6885)
parent
0fac7c2b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
8 deletions
+12
-8
document/middleware.ts
+10
-7
document/next.config.ts
+2
-1
No files found.
document/middleware.ts
View file @
45c9761d
...
...
@@ -88,13 +88,15 @@ const prefixMap: Record<string, string> = {
const
i18nMiddleware
=
createI18nMiddleware
(
i18n
);
function
applyRedirectMaps
(
path
:
string
):
string
|
null
{
const
normalizedPath
=
path
.
length
>
1
?
path
.
replace
(
/
\/
+$/
,
''
)
:
path
;
function
normalizePath
(
path
:
string
)
{
return
path
.
length
>
1
?
path
.
replace
(
/
\/
+$/
,
''
)
:
path
;
}
if
(
normalizedPath
in
exactMap
)
return
exactMap
[
normalizedPath
];
function
applyRedirectMaps
(
path
:
string
):
string
|
null
{
if
(
path
in
exactMap
)
return
exactMap
[
path
];
for
(
const
[
oldPrefix
,
newPrefix
]
of
Object
.
entries
(
prefixMap
))
{
if
(
normalizedP
ath
.
startsWith
(
oldPrefix
))
{
return
newPrefix
+
normalizedP
ath
.
slice
(
oldPrefix
.
length
);
if
(
p
ath
.
startsWith
(
oldPrefix
))
{
return
newPrefix
+
p
ath
.
slice
(
oldPrefix
.
length
);
}
}
return
null
;
...
...
@@ -126,7 +128,7 @@ export default function middleware(request: NextRequest) {
// Legacy /docs/* URLs: strip the /docs prefix and run redirect-match.
// Always 301 to the canonical (no-/docs) path, even if no map entry matches.
if
(
pathWithoutLang
===
'/docs'
||
pathWithoutLang
.
startsWith
(
'/docs/'
))
{
const
stripped
=
pathWithoutLang
.
slice
(
'/docs'
.
length
);
// '' for /docs, /foo for /docs/foo
const
stripped
=
normalizePath
(
pathWithoutLang
)
.
slice
(
'/docs'
.
length
);
// '' for /docs, /foo for /docs/foo
const
mapped
=
applyRedirectMaps
(
stripped
);
const
finalPath
=
mapped
??
stripped
;
return
NextResponse
.
redirect
(
createRedirectUrl
(
finalPath
,
request
,
lang
),
301
);
...
...
@@ -134,7 +136,8 @@ export default function middleware(request: NextRequest) {
// Non-/docs paths still consult the same maps so that direct hits on old
// canonical paths (e.g. /upgrading) get redirected to their new home.
const
mapped
=
applyRedirectMaps
(
pathWithoutLang
);
const
normalizedPath
=
normalizePath
(
pathWithoutLang
);
const
mapped
=
applyRedirectMaps
(
normalizedPath
);
if
(
mapped
!==
null
&&
mapped
!==
pathWithoutLang
)
{
return
NextResponse
.
redirect
(
createRedirectUrl
(
mapped
,
request
,
lang
),
301
);
}
...
...
document/next.config.ts
View file @
45c9761d
...
...
@@ -3,10 +3,11 @@ import type { NextConfig } from 'next';
const
withMDX
=
createMDX
();
const
config
:
NextConfig
=
{
const
config
:
NextConfig
=
{
output
:
'standalone'
,
reactStrictMode
:
true
,
compress
:
true
,
skipTrailingSlashRedirect
:
true
,
async
headers
()
{
return
[
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment