Redirects working locally but not on preview deploys or production

My app is at rav-tools.netlify.app

I have setup a redirect for the functions calls in my netlify.toml:

[build]
  command = "astro build"
  functions = "netlify/functions"
  publish = "dist"
[functions]
  node_bundler = "esbuild"
[[redirects]]
  from = "/api/*"
  to = ".netlify/functions/:splat"
  status = 200

This works fine locally, when running netlify dev; the /api/myEndpoint route works.

But on preview or production deploys, it returns HTTP 500 and no content. Using the other path .netlify/functions/myEndpoint works on the deployed version.

I don’t see any errors in the logs. I have even tried to unlink and relink the repo and redeploy with no luck.

It detects the redirect when building because I can see this in the Netlify UI for that site:

**1 redirect rule processed**

All redirect rules deployed without errors."

When deployed:

$ curl -v https://rav-tools.netlify.app/api/calculateDate
*   Trying 52.58.254.253:443...
* TCP_NODELAY set
* Connected to rav-tools.netlify.app (52.58.254.253) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: /etc/ssl/certs
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
* TLSv1.3 (IN), TLS handshake, Certificate (11):
* TLSv1.3 (IN), TLS handshake, CERT verify (15):
* TLSv1.3 (IN), TLS handshake, Finished (20):
* TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.3 (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / TLS_AES_128_GCM_SHA256
* ALPN, server accepted to use h2
* Server certificate:
*  subject: C=US; ST=California; L=San Francisco; O=Netlify, Inc; CN=*.netlify.app
*  start date: Dec 21 00:00:00 2022 GMT
*  expire date: Jan 21 23:59:59 2024 GMT
*  subjectAltName: host "rav-tools.netlify.app" matched cert's "*.netlify.app"
*  issuer: C=US; O=DigiCert Inc; CN=DigiCert TLS Hybrid ECC SHA384 2020 CA1
*  SSL certificate verify ok.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x5601679acb60)
> GET /api/calculateDate HTTP/2
> Host: rav-tools.netlify.app
> user-agent: curl/7.68.0
> accept: */*
>
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* Connection state changed (MAX_CONCURRENT_STREAMS == 250)!
< HTTP/2 500
< age: 0
< date: Tue, 29 Aug 2023 13:02:08 GMT
< server: Netlify
< strict-transport-security: max-age=31536000; includeSubDomains; preload
< x-nf-request-id: 01H90P66250NC875FT18WHFZYS
< content-length: 0
<
* Connection #0 to host rav-tools.netlify.app left intact




$ curl -v https://rav-tools.netlify.app/.netlify/functions/calculateDate
*   Trying 34.159.132.250:443...
* TCP_NODELAY set
* Connected to rav-tools.netlify.app (34.159.132.250) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: /etc/ssl/certs
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
* TLSv1.3 (IN), TLS handshake, Certificate (11):
* TLSv1.3 (IN), TLS handshake, CERT verify (15):
* TLSv1.3 (IN), TLS handshake, Finished (20):
* TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.3 (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / TLS_AES_128_GCM_SHA256
* ALPN, server accepted to use h2
* Server certificate:
*  subject: C=US; ST=California; L=San Francisco; O=Netlify, Inc; CN=*.netlify.app
*  start date: Dec 21 00:00:00 2022 GMT
*  expire date: Jan 21 23:59:59 2024 GMT
*  subjectAltName: host "rav-tools.netlify.app" matched cert's "*.netlify.app"
*  issuer: C=US; O=DigiCert Inc; CN=DigiCert TLS Hybrid ECC SHA384 2020 CA1
*  SSL certificate verify ok.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x55f14255db60)
> GET /.netlify/functions/calculateDate HTTP/2
> Host: rav-tools.netlify.app
> user-agent: curl/7.68.0
> accept: */*
>
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* Connection state changed (MAX_CONCURRENT_STREAMS == 250)!
< HTTP/2 400
< age: 1
< cache-control: no-cache
< content-type: text/plain; charset=utf-8
< date: Tue, 29 Aug 2023 13:02:18 GMT
< server: Netlify
< strict-transport-security: max-age=31536000; includeSubDomains; preload
< x-nf-request-id: 01H90P6FJXHFTZMXZQFDMCCT4G
<
* Connection #0 to host rav-tools.netlify.app left intact
{"message":"Missing all parameters"}

Locally with netlify dev:

$ curl -v http://localhost:8888/api/calculateDate
*   Trying 127.0.0.1:8888...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8888 (#0)
> GET /api/calculateDate HTTP/1.1
> Host: localhost:8888
> User-Agent: curl/7.68.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 400 Bad Request
< server: Netlify
< x-nf-request-id: 01H90P9G1DF68DABGBKXQENXRR
< x-powered-by: Express
< date: Tue, 29 Aug 2023 13:03:56 GMT
< connection: close
< transfer-encoding: chunked
<
* Closing connection 0
{"message":"Missing all parameters"}




$ curl -v http://localhost:8888/.netlify/functions/calculateDate
*   Trying 127.0.0.1:8888...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8888 (#0)
> GET /.netlify/functions/calculateDate HTTP/1.1
> Host: localhost:8888
> User-Agent: curl/7.68.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 400 Bad Request
< server: Netlify
< x-nf-request-id: 01H90P9QYNW47JP7DPNS6WYYDN
< x-powered-by: Express
< date: Tue, 29 Aug 2023 13:04:04 GMT
< connection: close
< transfer-encoding: chunked
<
* Closing connection 0
{"message":"Missing all parameters"}

Logs:

2:53:55 PM: Starting post processing
2:53:55 PM: Skipping HTML post processing
2:53:55 PM: Post processing - header rules
2:53:56 PM: Post processing - redirect rules
2:53:56 PM: Post processing done
2:53:56 PM: Section completed: postprocessing
2:53:57 PM: Site is live ✨
2:53:35 PM: build-image version: 6cae66f783f2b7ff8e3a9cdbb5031761f0b47719 (focal)
2:53:35 PM: buildbot version: cb74d097ea8f76bcaa16d435b6bf29d5a1715ede
2:53:36 PM: Fetching cached dependencies
2:53:36 PM: Starting to download cache of 132.8MB
2:53:37 PM: Finished downloading cache in 1.638s
2:53:37 PM: Starting to extract cache
2:53:39 PM: Finished extracting cache in 1.894s
2:53:39 PM: Finished fetching cache in 3.58s
2:53:39 PM: Starting to prepare the repo for build
2:53:40 PM: Preparing Git Reference refs/heads/master
2:53:41 PM: Starting to install dependencies
2:53:41 PM: Python version set to 3.8
2:53:41 PM: Attempting Ruby version 2.7.2, read from environment
2:53:42 PM: Using Ruby version 2.7.2
2:53:42 PM: Started restoring cached go cache
2:53:42 PM: Finished restoring cached go cache
2:53:43 PM: go version go1.19.12 linux/amd64
2:53:44 PM: Using PHP version 8.0
2:53:45 PM: Started restoring cached Node.js version
2:53:45 PM: Finished restoring cached Node.js version
2:53:46 PM: v18.17.1 is already installed.
2:53:46 PM: Now using node v18.17.1 (npm v9.6.7)
2:53:46 PM: Enabling Node.js Corepack
2:53:46 PM: Started restoring cached build plugins
2:53:46 PM: Finished restoring cached build plugins
2:53:46 PM: Started restoring cached corepack dependencies
2:53:46 PM: Finished restoring cached corepack dependencies
2:53:46 PM: No npm workspaces detected
2:53:46 PM: Started restoring cached node modules
2:53:46 PM: Finished restoring cached node modules
2:53:46 PM: Installing npm packages using npm version 9.6.7
2:53:50 PM: changed 1 package, and audited 1778 packages in 3s
2:53:50 PM: 320 packages are looking for funding
2:53:50 PM:   run `npm fund` for details
2:53:50 PM: 1 moderate severity vulnerability
2:53:50 PM: To address all issues, run:
2:53:50 PM:   npm audit fix
2:53:50 PM: Run `npm audit` for details.
2:53:50 PM: npm packages installed
2:53:50 PM: Install dependencies script success
2:53:50 PM: Starting build script
2:53:51 PM: Detected 1 framework(s)
2:53:51 PM: astro at version 2.10.12
2:53:51 PM: Section completed: initializing
2:53:53 PM: ​
2:53:53 PM: Netlify Build                                                 
2:53:53 PM: ────────────────────────────────────────────────────────────────
2:53:53 PM: ​
2:53:53 PM: ❯ Version
2:53:53 PM:   @netlify/build 29.20.6
2:53:53 PM: ​
2:53:53 PM: ❯ Flags
2:53:53 PM:   baseRelDir: true
2:53:53 PM:   buildId: 64edea3e9a09a215920831d0
2:53:53 PM:   deployId: 64edea3e9a09a215920831d2
2:53:53 PM: ​
2:53:53 PM: ❯ Current directory
2:53:53 PM:   /opt/build/repo
2:53:53 PM: ​
2:53:53 PM: ❯ Config file
2:53:53 PM:   /opt/build/repo/netlify.toml
2:53:53 PM: ​
2:53:53 PM: ❯ Context
2:53:53 PM:   production
2:53:53 PM: ​
2:53:53 PM: build.command from netlify.toml                               
2:53:53 PM: ────────────────────────────────────────────────────────────────
2:53:53 PM: ​
2:53:53 PM: $ astro build
2:53:54 PM: 12:53:54 PM [content] No content directory found. Skipping type generation.
2:53:54 PM: 12:53:54 PM [build] output target: static
2:53:54 PM: 12:53:54 PM [build] Collecting build info...
2:53:54 PM: 12:53:54 PM [build] Completed in 72ms.
2:53:54 PM: 12:53:54 PM [build] Building static entrypoints...
2:53:55 PM: 12:53:55 PM [build] Completed in 577ms.
2:53:55 PM: 
2:53:55 PM:  building client 
2:53:55 PM: Completed in 23ms.
2:53:55 PM: 
2:53:55 PM: 
2:53:55 PM:  generating static routes 
2:53:55 PM: ▶ src/pages/index.astro
2:53:55 PM:   └─ /index.html (+65ms)
2:53:55 PM: Completed in 69ms.
2:53:55 PM: 
2:53:55 PM: 12:53:55 PM [build] 1 page(s) built in 749ms
2:53:55 PM: 12:53:55 PM [build] Complete!
2:53:55 PM: ​
2:53:55 PM: (build.command completed in 1.5s)
2:53:55 PM: ​
2:53:55 PM: Functions bundling                                            
2:53:55 PM: ────────────────────────────────────────────────────────────────
2:53:55 PM: ​
2:53:55 PM: Packaging Functions from netlify/functions directory:
2:53:55 PM:  - calculateDate.ts
2:53:55 PM: ​
2:53:55 PM: ​
2:53:55 PM: (Functions bundling completed in 120ms)
2:53:55 PM: ​
2:53:55 PM: Deploy site                                                   
2:53:55 PM: ────────────────────────────────────────────────────────────────
2:53:55 PM: ​
2:53:55 PM: Starting to deploy site from 'dist'
2:53:55 PM: Calculating files to upload
2:53:55 PM: 0 new files to upload
2:53:55 PM: 0 new functions to upload
2:53:55 PM: Section completed: deploying
2:53:55 PM: Site deploy was successfully initiated
2:53:55 PM: ​
2:53:55 PM: (Deploy site completed in 343ms)
2:53:55 PM: ​
2:53:55 PM: Netlify Build Complete                                        
2:53:55 PM: ────────────────────────────────────────────────────────────────
2:53:55 PM: ​
2:53:55 PM: (Netlify Build completed in 2.5s)
2:53:56 PM: Caching artifacts
2:53:56 PM: Started saving node modules
2:53:56 PM: Finished saving node modules
2:53:56 PM: Started saving build plugins
2:53:56 PM: Finished saving build plugins
2:53:56 PM: Started saving corepack cache
2:53:56 PM: Finished saving corepack cache
2:53:56 PM: Started saving pip cache
2:53:56 PM: Finished saving pip cache
2:53:56 PM: Started saving emacs cask dependencies
2:53:56 PM: Finished saving emacs cask dependencies
2:53:56 PM: Started saving maven dependencies
2:53:56 PM: Finished saving maven dependencies
2:53:56 PM: Started saving boot dependencies
2:53:56 PM: Finished saving boot dependencies
2:53:56 PM: Started saving rust rustup cache
2:53:56 PM: Finished saving rust rustup cache
2:53:56 PM: Started saving go dependencies
2:53:56 PM: Finished saving go dependencies
2:53:56 PM: Build script success
2:53:56 PM: Section completed: building
2:53:57 PM: Uploading Cache of size 132.9MB
2:53:58 PM: Section completed: cleanup
2:53:58 PM: Finished processing build request in 23.28s

hi there, before we dig in, did you see this brand new guide on debugging redirects?

I strongly suggest you give it a thorough read through and see if this fixes your problem:

if not, please post again, and we’ll try and troubleshoot.