diff --git a/docs/api-reference/next.config.js/rewrites.md b/docs/api-reference/next.config.js/rewrites.md index 16ae2b533df8..47571668dfb2 100644 --- a/docs/api-reference/next.config.js/rewrites.md +++ b/docs/api-reference/next.config.js/rewrites.md @@ -300,15 +300,20 @@ module.exports = { Examples -Rewrites allow you to rewrite to an external url. This is especially useful for incrementally adopting Next.js. +Rewrites allow you to rewrite to an external url. This is especially useful for incrementally adopting Next.js. The following is an example rewrite for redirecting the `/blog` route of your main app to an external site. ```js module.exports = { async rewrites() { return [ + { + source: '/blog', + destination: 'https://example.com/blog', + }, { source: '/blog/:slug', destination: 'https://example.com/blog/:slug', // Matched parameters can be used in the destination @@ -318,6 +323,26 @@ module.exports = { } ``` +If you're using `trailingSlash: true`, you also need to insert a trailing slash in the `source` paramater. If the destination server is also expecting a trailing slash it should be included in the `destination` parameter as well. + +```js +module.exports = { + trailingSlash: 'true', + async rewrites() { + return [ + { + source: '/blog/', + destination: 'https://example.com/blog/', + }, + { + source: '/blog/:path*/', + destination: 'https://example.com/blog/:path*/', + }, + ] + }, +} +``` + ### Incremental adoption of Next.js You can also have Next.js fall back to proxying to an existing website after checking all Next.js routes.