What are best practices for managing a large number of redirects on a website that has gone through multiple redesigns over the years?
Short answer
Keep your redirect rules organized in a clearly documented list, regularly audit and remove ones that are no longer needed, avoid chaining multiple redirects together since each hop adds delay, and consider storing very large redirect lists in a database or external service…
Advertisement
AModel answer
Keep your redirect rules organized in a clearly documented list, regularly audit and remove ones that are no longer needed, avoid chaining multiple redirects together since each hop adds delay, and consider storing very large redirect lists in a database or external service rather than directly inside your configuration file if the list grows into the thousands.
// Avoid chains: redirect directly to the final destination
// Bad: /old -> /middle -> /new
// Good: /old -> /new
module.exports = {
async redirects() {
return [{ source: '/old', destination: '/new', permanent: true }];
}
};Real-world example
A company that has redesigned its website three times over the years audits its growing list of redirects, removing outdated chains and consolidating them into direct redirects to improve page load speed.
Likely follow-ups
- How many redirect hops is considered too many for performance and SEO?
- When should redirects be moved out of next.config.js and into a database instead?
Related topics