#title
1 messages · Page 1 of 1 (latest)
Based on the information provided in the knowledge sources, it appears that you're encountering an issue with rewrites in Next.js when trying to proxy requests from one domain to another, specifically involving the _next/static directory. This is a common challenge when setting up rewrites, especially with basePath and external URLs. Let me provide some insights and potential solutions:
- First, ensure that you're using the correct rewrite configuration in your
next.config.jsfile. The rewrite should include the_nextpath. Here's an example of how you might set this up:
module.exports = {
async rewrites() {
return [
{
source: '/docs/:path*',
destination: '<https://docs.example.com/:path*',>
},
{
source: '/docs/_next/:path*',
destination: '<https://docs.example.com/_next/:path*',>
}
]
},
}
-
If you're using
basePath, make sure it's correctly configured and that your rewrites take it into account. ThebasePathcan interfere with rewrites if not handled properly Next.js Docs: Rewrites with basePath support. -
When rewriting to an external URL, ensure that the destination server is set up to handle the incoming requests correctly, including for static assets.
-
If you're deploying to a platform like Vercel or Netlify, be aware that there might be platform-specific considerations. For instance, there was a reported issue with basePath and rewrites on these platforms Github Issue: Using basePath with rewrites to proxy to another Next.js site fails when deployed to Netlify or Vercel.
-
Consider using wildcard path matching in your rewrites to ensure all necessary paths are covered:
module.exports = {
async rewrites() {
return [
{
source: '/docs/:path*',
destination: '<https://docs.example.com/:path*',>
}
]
},
}
If these suggestions don't resolve your issue, you might need to investigate further, possibly by examining network requests in your browser's developer tools to see exactly which requests for static assets are failing.