[英]Next.js 301: How to redirect from source with query to destination without query
如果有人幫助我,我將不勝感激:
https://example.com/category/results/refine?dealers=123&inv=true&sellertypes=dealer
dealers
和inv
密鑰,我想實施 SSR 永久 301 重定向到目標 URL,例如https://example.com/
。next.config.ts
中實現了以下代碼: async redirects() { return [ { source: "/category/results/refine", has: [ { type: "query", key: "dealers", }, { type: "query", key: "inv", value: "true", }, ], destination: "/", permanent: true, statusCode: 301, }, }
https://example.com/
而是https://example.com/?dealers=123&inv=true&sellertypes=dealer
。 我的意思是,來自源 URL 的查詢堅持到目標 URL。這不是我所期望的。看起來這不能通過nextjs
配置來實現——文檔指出:
應用重定向時,請求中提供的任何查詢值都將傳遞到重定向目標。 例如,看下面的重定向配置:當請求/old-blog/post-1?hello=world時,客戶端會被重定向到/blog/post-1?hello=world。
你有兩個選擇。
實現自定義服務器,然后進行路徑匹配和刪除查詢參數的代碼
實施代理,如 nginx 或 CDN,為您提供精細的路由控制。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.