|
|
@@ -100,6 +100,50 @@ app.use('/thumbs/v1', require('./routes/res/thumbs'));
|
|
|
app.use('/proxy', require('./routes/proxy'));
|
|
|
|
|
|
|
|
|
+// 旧多语言前缀 URL 统一 301 到 v2 URL,保留 query 参数以迁移 SEO 信号。
|
|
|
+app.use((req, res, next) => {
|
|
|
+ const match = req.path.match(/^\/(en|zh|es|pt|ja)(\/.*)?$/);
|
|
|
+ if (!match) return next();
|
|
|
+
|
|
|
+ const tail = match[2] || '/';
|
|
|
+ const query = req.url.includes('?') ? req.url.slice(req.url.indexOf('?')) : '';
|
|
|
+
|
|
|
+ // 将 "slug-id" 形式提取出真实 id(兼容旧详情 URL)。
|
|
|
+ const extractRealId = (str) => {
|
|
|
+ const last = (str || '').split('-').pop();
|
|
|
+ return /^[a-f0-9]{24}$/i.test(last) ? last : str;
|
|
|
+ };
|
|
|
+
|
|
|
+ let target = tail;
|
|
|
+
|
|
|
+ if (tail === '/' || tail === '') {
|
|
|
+ target = '/';
|
|
|
+ } else if (/^\/coloring-page\//.test(tail)) {
|
|
|
+ const str = tail.replace(/^\/coloring-page\//, '');
|
|
|
+ target = `/coloring-page/${extractRealId(str)}`;
|
|
|
+ } else if (/^\/(album|coloring-page-album)\//.test(tail)) {
|
|
|
+ const id = tail.replace(/^\/(album|coloring-page-album)\//, '');
|
|
|
+ target = `/coloring-page-album/${id}`;
|
|
|
+ } else if (tail === '/gallery') {
|
|
|
+ target = '/coloring-page-gallery';
|
|
|
+ } else if (tail === '/videos') {
|
|
|
+ target = '/video-coloring-pages';
|
|
|
+ } else if (/^\/coloring-page-video\//.test(tail)) {
|
|
|
+ const id = tail.replace(/^\/coloring-page-video\//, '');
|
|
|
+ target = `/video-coloring-page/${id}`;
|
|
|
+ } else if (tail === '/albums') {
|
|
|
+ target = '/coloring-page-albums';
|
|
|
+ } else if (/^\/(tag|category)\//.test(tail)) {
|
|
|
+ const tag = tail.replace(/^\/(tag|category)\//, '') || 'latest';
|
|
|
+ target = `/coloring-pages?tag=${encodeURIComponent(tag)}`;
|
|
|
+ } else if (tail === '/tag' || tail === '/category') {
|
|
|
+ target = '/coloring-pages?tag=latest';
|
|
|
+ }
|
|
|
+
|
|
|
+ return res.redirect(301, `${target}${query}`);
|
|
|
+});
|
|
|
+
|
|
|
+
|
|
|
//v2
|
|
|
app.use('/', require('./routes/v2/index')); // 首页和具体分类合集页
|
|
|
app.use('/coloring-page', require('./routes/v2/detail')) // 详情页
|