Capítulo 415 de 456
Redirects an incoming request path to a different destination path, defined via the redirects key in next.config.js (Pages Router). Checked before the filesystem.
true → 308 status (cached forever by clients/search engines), false → 307 (temporary, not cached). Mutually exclusive with statusCode (for custom codes, e.g. old HTTP clients).false to opt a redirect out of automatic basePath/locale prefixing.header, cookie, host, query (same shape as headers/rewrites).Link/router.push unless a matching Proxy is present.module.exports = {
redirects() {
return [
{
source: '/old-blog/:slug',
destination: '/news/:slug',
permanent: true,
},
]
},
}
/old-blog/post-1?hello=world vira /news/post-1?hello=world.| Version | Changes |
|---|---|
| v13.3.0 | missing added |
| v10.2.0 | has added |
| v9.5.0 | redirects added |
/ antes de :param no source/destination: trata o path como string literal e pode causar loop infinito de redirect.permanent e statusCode juntos: são mutuamente exclusivos./old-blog/:slug não pega /old-blog/a/b), use * para isso.redirects() sozinha só cobre navegação servidor.getStaticProps e getServerSideProps.source, path matching, has/missing.