Next.js Rewrite request error

Hi, @irorochad!

From what I can see, your configuration rewrote the main document requests but didn’t properly handle the associated static assets which led to a functional but unstyled documentation page. This is why you saw the content of your docs but without the correct styling and potentially missing some functionality provided by JavaScript files.

You’ll need to update your vercel.json file to add a second rewrite rule specifically for static assets and include a headers configuration for security. I’ve shared an example below, what it does is rewrites main content requests from /docs to docs.maindomain.com and static asset requests (in the /_next directory) to the correct location on docs.maindomain.com.

Example
{
  "rewrites": [
    {
      "source": "/docs/:path*",
      "destination": "https://docs.maindomain.com/:path*"
    },
    {
      "source": "/docs/_next/:path*",
      "destination": "https://docs.maindomain.com/_next/:path*"
    }
  ],
  "headers": [
    {
      "source": "/docs/(.*)",
      "headers": [
        {
          "key": "X-Frame-Options",
          "value": "SAMEORIGIN"
        }
      ]
    }
  ]
}

After updating and deploying this configuration, your documentation should load correctly, including all styles and static assets. If issues persist, verify your documentation site setup, check for absolute URLs, and clear your browser cache.

Let us know how you get on!