Skip to content

[BUG] next.config rewrites result in request URL being rewrite destination #848

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
arvinpoddar opened this issue May 1, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@arvinpoddar
Copy link

arvinpoddar commented May 1, 2025

Describe the bug

When I have a rewrite rule in my next.config.ts with a destination to an API route, the request URL received by the API route is that of the destination. This is different behavior from the same app deployed on Vercel (or running the app locally), where the request URL received by the API route corresponds to the originally requested URL from the client.

Video demonstration:

demo.mp4

Steps to reproduce

Reproduction repo (this was used for the video above, and can be directly deployed to both Cloudflare and Vercel): https://github.com/arvinpoddar/cloudflare-rewrites-repro

Reproduction steps:

  1. In your next.config.ts, create a rewrite rule that rewrites /about to /api/hello.
  2. Create a /api/hello/route.ts, and console.log the incoming request URL.
  3. Navigate to /about in your browser
  4. When locally running the app, or when the app is deployed to Vercel, the logged request's URL path will be /about, which is the originally requested path.
  5. When the same app is deployed to Cloudflare, the logged request's URL path will be /api/hello, which is the destination of the rewrite.

Expected behavior

I would expect the request URL to be that of the original client request, rather than the destination of the rewrite. This would be consistent with the app's behavior locally and on Vercel.

@opennextjs/cloudflare version

~1.0.0-beta.0 || ^1.0.0

Wrangler version

^4.13.2

next info output

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.3.0: Thu Jan  2 20:24:23 PST 2025; root:xnu-11215.81.4~3/RELEASE_ARM64_T6020
  Available memory (MB): 16384
  Available CPU cores: 10
Binaries:
  Node: 21.6.1
  npm: 10.2.4
  Yarn: 1.22.22
  pnpm: 10.7.0
Relevant Packages:
  next: 15.3.1 // Latest available version is detected (15.3.1).
  eslint-config-next: 15.3.1
  react: 19.1.0
  react-dom: 19.1.0
  typescript: 5.8.3
Next.js Config:
  output: N/A

Additional context

No response

@arvinpoddar arvinpoddar added the bug Something isn't working label May 1, 2025
@vicb
Copy link
Contributor

vicb commented May 2, 2025

@conico974 should I transfer this issue to the aws repo?

@conico974
Copy link
Contributor

Yeah the issue should be fixed there

@vicb vicb transferred this issue from opennextjs/opennextjs-cloudflare May 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants