Next.js
/Advanced
Rewrites
Definition
Masking a destination URL while keeping the user on the original requested URL.
Explain Like I'm New
A Redirect changes the URL in the user's browser bar. A Rewrite secretly fetches data from somewhere else, but keeps the browser URL looking exactly the same. It's a proxy.
Real World Example
Your Next.js app is at `mycompany.com`. You have a totally separate WordPress blog at `blog.wp-hosting.com`. You use a Rewrite so that when a user visits `mycompany.com/blog`, Next.js secretly fetches the WordPress site and shows it, making it look like one seamless website.
Common Use Cases
- •Incremental adoption/migration
- •Proxying external APIs to avoid CORS errors
Interactive Example
Loading...
Console output will appear here...
Interview Questions
basic
- Does a Rewrite change the URL displayed in the user's browser?
intermediate
- How can Rewrites solve CORS (Cross-Origin Resource Sharing) errors?