Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vcci-news-frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Văn Hoàng
vcci-news-frontend
Commits
1094de1d
Commit
1094de1d
authored
Oct 20, 2026
by
Phạm Quang Bảo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
u
parent
e614971d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
3036 additions
and
0 deletions
+3036
-0
legacy-redirect-map.ts
src/lib/legacy-redirect-map.ts
+2987
-0
proxy.ts
src/proxy.ts
+49
-0
No files found.
src/lib/legacy-redirect-map.ts
0 → 100644
View file @
1094de1d
This source diff could not be displayed because it is too large. You can
view the blob
instead.
src/proxy.ts
0 → 100644
View file @
1094de1d
import
{
NextRequest
,
NextResponse
}
from
"next/server"
;
import
{
LEGACY_ID_MAP
,
LEGACY_SLUG_MAP
}
from
"@/lib/legacy-redirect-map"
;
/**
* Redirect cac link cu cua site WordPress ve slug hien tai trong CMS moi:
* - ?p=<id> (link kieu ?p=11051)
* - .../ten-bai.html (permalink cu co duoi .html)
* - /ten-bai (slug cu bi doi)
* Map tu dong tao boi migration/scripts/build-redirect-map.mjs.
*
* Next.js 16: middleware.ts -> proxy.ts (cu), ham export 'proxy'.
*/
export
default
function
proxy
(
req
:
NextRequest
)
{
// 1. ?p=<id>
const
p
=
req
.
nextUrl
.
searchParams
.
get
(
"p"
);
if
(
p
)
{
const
slug
=
LEGACY_ID_MAP
[
p
];
if
(
slug
)
{
return
NextResponse
.
redirect
(
new
URL
(
"/"
+
slug
,
req
.
nextUrl
.
origin
),
308
);
}
}
// 2. duoi .html
const
pathname
=
req
.
nextUrl
.
pathname
;
if
(
pathname
.
toLowerCase
().
endsWith
(
".html"
))
{
const
trimmed
=
pathname
.
slice
(
0
,
-
5
);
const
last
=
trimmed
.
split
(
"/"
).
filter
(
Boolean
).
pop
();
if
(
last
)
{
const
target
=
LEGACY_SLUG_MAP
[
last
]
??
last
;
return
NextResponse
.
redirect
(
new
URL
(
"/"
+
target
+
req
.
nextUrl
.
search
,
req
.
nextUrl
.
origin
),
308
);
}
}
// 3. slug cu bi doi
const
clean
=
pathname
.
replace
(
/
\/
+$/
,
""
).
replace
(
/^
\/
/
,
""
);
const
mapped
=
LEGACY_SLUG_MAP
[
clean
];
if
(
mapped
)
{
return
NextResponse
.
redirect
(
new
URL
(
"/"
+
mapped
+
req
.
nextUrl
.
search
,
req
.
nextUrl
.
origin
),
308
);
}
return
NextResponse
.
next
();
}
export
const
config
=
{
matcher
:
[
"/((?!api|admin|uploads|_next/static|_next/image|images/|public/|favicon.ico|thumbnail.png|robots.txt|sitemap.xml|ads.txt).*)"
,
],
};
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