next.config.js 파일 내에 작성해야하며, 서버를 재시작해야 적용된다. 둘 다 pattern matching을 지원하고 객체 배열을 return 해야한다.
next.config.js에서 이루어짐
async redirects() {
return [
{
source: "/old",
destination: "/new",
permanent: false,
},
];
}
pattern matching 지원.
async rewrites() {
return [
{
source: "/api/movies",
destination: `https://api.themoviedb.org/3/movie/popular?api_key=${API_KEY}`,
},
];
}
destination으로 redirect 돼도 URL에 표시되지 않아 API key와 같이 숨겨야 할 정보들을 숨길 수 있음.