Category: Vercel and hosting

Vercel: rewrite directs requests to 404 instead of the application

Read this guide in Polish

After adding rewrite some routes or API shows 404 despite the existence of appropriate pages. Routing rules can capture requests in the wrong order or direct them to an unexistent path.

How to determine the source of the error

Save the original URL and final URL of requests in response and order of rules.

Check the rewrites configuration, redirects and service of routes in the framework.

What to do step by step

1. Narrow the pattern rewrite to the right prefix and direct it to the actual existing route.

2 . Add a test for regular pages, APIs, and static files so that one rule does not absorb the entire application.

How to check the score

Each scheduled route returns the correct content and the others still give the expected 404.

What to do

Do not set the universal rewrite to the home page, because it may mask a non-existent URL.