#title

1 messages · Page 1 of 1 (latest)

solid coveBOT
#

Hi @brittle plume. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

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:

  1. First, ensure that you're using the correct rewrite configuration in your next.config.js file. The rewrite should include the _next path. 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*',>
      }
    ]
  },
}
  1. If you're using basePath, make sure it's correctly configured and that your rewrites take it into account. The basePath can interfere with rewrites if not handled properly Next.js Docs: Rewrites with basePath support.

  2. When rewriting to an external URL, ensure that the destination server is set up to handle the incoming requests correctly, including for static assets.

  3. 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.

  4. 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.

Remember that rewriting to external URLs can be complex, especially when dealing with static assets. If you continue to face issues, you might want to consider alternative approaches, such as using a reverse proxy at the server level instead of relying solely on Next.js rewrites.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: