import { sendRedirect } from 'h3' /** * 旧模块名 → 新模块名(按模块名单数命名)301 重定向 * * 2026-07-20 起 URL 规范统一为模块名单数: * 新闻 /article、产品 /product、案例 /case(详情与栏目同一词根,靠 navId 判定)。 * 改名前的旧链接需兼容,避免已收录 / 外链失效: * /news、/newss → /article * /products → /product * /cases → /case * 新规范路径(/article、/product、/case)不在映射内,不重定向。 */ export default defineEventHandler((event) => { const path = event.path || '' if ( path.startsWith('/api/') || path.startsWith('/_') || /\.(?:ico|png|jpe?g|gif|svg|css|js|map|woff2?|ttf|txt)$/i.test(path) ) { return } const OLD_TO_NEW: Array<[string, string]> = [ ['/news', '/article'], ['/newss', '/article'], ['/products', '/product'], ['/cases', '/case'] ] for (const [oldPrefix, newPrefix] of OLD_TO_NEW) { if (path === oldPrefix || path.startsWith(oldPrefix + '/')) { const rest = path.slice(oldPrefix.length) // '' 或 '/xxx' return sendRedirect(event, newPrefix + rest, 301) } } })