Next.js · Junior · Question 56 of 75
How do you redirect the old /blog/:slug URLs to /news/:slug for every request, without code in pages?
// next.config.ts
async redirects() {
return [{ source: '/blog/:slug', destination: '/news/:slug', permanent: true }]
}- ✓Correct answer: With
redirects()innext.config.ts - 2By creating an empty page at every old URL
- 3With a
<meta http-equiv="refresh">tag in the root layout
Explanation
Config redirects run before the filesystem routes are matched. For many dynamic redirects (e.g. from a database), use proxy.ts instead.