nextjs - 💡(How to fix) Fix 16.2.0 Regression: proxy not following matcher rule on Vercel [2 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#91726Fetched 2026-04-08 01:07:11
View on GitHub
Comments
2
Participants
3
Timeline
7
Reactions
0
Author
Timeline (top)
commented ×2labeled ×2closed ×1issue_type_added ×1

Code Example

Vercel deployment
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/viztor/reproduction-next-16-2-proxy-rewrite

To Reproduce

Need to deploy to vercel to see the effect, working as expected on local, the minimal reproduction is already deployed, check it out

Current vs. Expected behavior

Current behavior is matcher rule is being ignored regarding specific built-ins like sitemap.ts and robot.txt

Provide environment information

Vercel deployment

Which area(s) are affected? (Select all that apply)

Internationalization (i18n)

Which stage(s) are affected? (Select all that apply)

Vercel (Deployed)

Additional context

Might be do to with how Vercel handles Next.js edge function runtime and how next.js internally handles it. There might be some entanglement in how rewrites are enforced internally that's causing this issue. It was initially thought as a bug on Vercel, read support case on #1048169 if you can, especially since local dev server works as expected. Last official 16.1.7 works as expected on Vercel, latest 16.2.0 version works as expected on local dev server, but not on Vercel

extent analysis

Fix Plan

The fix involves updating the next.config.js file to correctly handle rewrites for built-in files like sitemap.xml and robots.txt on Vercel.

  • Update next.config.js to include the following code:
module.exports = {
  //... other configurations ...
  async rewrites() {
    return [
      {
        source: '/sitemap.xml',
        destination: '/api/sitemap', // assuming you have an API route for sitemap
      },
      {
        source: '/robots.txt',
        destination: '/api/robots', // assuming you have an API route for robots.txt
      },
    ]
  },
}
  • Create API routes for sitemap.xml and robots.txt in pages/api directory:
// pages/api/sitemap.js
export default async function handler(req, res) {
  // generate sitemap content
  const sitemapContent = 'your sitemap content here';
  res.setHeader('Content-Type', 'application/xml');
  res.write(sitemapContent);
  res.end();
}

// pages/api/robots.js
export default async function handler(req, res) {
  // generate robots.txt content
  const robotsContent = 'your robots.txt content here';
  res.setHeader('Content-Type', 'text/plain');
  res.write(robotsContent);
  res.end();
}

Verification

To verify the fix, redeploy your application to Vercel and check that the sitemap.xml and robots.txt files are being served correctly.

Extra Tips

  • Make sure to update your next.config.js file to include the correct rewrites for your built-in files.
  • If you're using a custom domain on Vercel, ensure that your rewrites are configured to handle the custom domain correctly.
  • You can test your rewrites locally by running npm run dev and accessing your application at http://localhost:3000.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING