Skip to content

Server returns 200 (soft 404) for non-existent routes instead of a real 404 #6463

Open

Description

@Alek99

Describe the bug

Reflex apps return HTTP 200 for URLs that don't correspond to any real page, serving the SPA fallback as the response body. This is a soft 404: the page doesn't exist, but the server signals success. Crawlers, AI agents, and SEO tooling all treat the response as a valid page and try to extract content from what is effectively an error state.

The root cause is that the SPA fallback is doing double duty. It's how Reflex resolves dynamic routes and other runtime-resolved paths and it's what gets served when a URL doesn't match anything. Both cases hit the same fallback, so the server can't distinguish "valid dynamic route" from "nonexistent page"

We need to be able to distinguish between the two

To Reproduce

  1. Deploy any Reflex app.
  2. Request a URL that doesn't map to a defined page, e.g. /this-page-does-not-exist.
  3. Observe: response is 200 OK with the SPA fallback HTML.
  4. Expected: 404 Not Found.

Activity

  1. added
    bug
    on May 6, 2026
  2. linear commented on May 6, 2026

    @linear
  3. adhami3310 commented on May 7, 2026

    @adhami3310
    Member

    on what level would you like this to be resolved? as it's typical for people in a production build to put something like Caddy/nginx, and since we produce static frontend we have no script to run there. it depends on the deployment

  4. masenf commented on May 7, 2026

    @masenf
    Collaborator

    At the time, this seemed like a better compromise than serving the 404 status for legitimate dynamic routes.

    Now that the ASGI server itself serves the exported frontend and knows what the dynamic routes are, we could add some smarts in the static file mount to align the HTTP status code based on the dynamic routes defined.

    But performance of production deployments will suffer if all the static file serving has to go through the python origin server.

  5. masenf commented on May 7, 2026

    @masenf
    Collaborator

    opened draft pr #6469 to start addressing this... turns out reflex run --env prod had the opposite problem in that it was returning 404 for actual legitimate dynamic routes. So 6469 solves that issue by adjusting the status code for requests that match a known route.

    The PR also writes out an app manifest JSON file that could be used to create config files for CDN/proxy servers to know which routes are legit or not; but in the short term at least, instead of always serving the spa fallback when the expected static file is missing, we could instead proxy those requests (with caching) to the origin server, and have the StaticFiles module do the lookup for whether the route is legit or not.

  6. Alek99 commented on May 7, 2026

    @Alek99
    MemberAuthor

    on what level would you like this to be resolved? as it's typical for people in a production build to put something like Caddy/nginx, and since we produce static frontend we have no script to run there. it depends on the deployment

    On a framework level

  7. adhami3310 commented on May 7, 2026

    @adhami3310
    Member

    On a framework level

    so only for reflex run --env prod? we could do that (as in the PR above), but that wouldn't fix

    Deploy any Reflex app

    that you put in the issue above, that fix would require reflex cloud coordination as well, which wouldn't fix it for people using caddy (like we do for most of our websites deployed right now), then we can separately fix for caddy (only for us, but maybe we can provide an example for others), but that wouldn't fix for nginx, which we could try another separate example for it

    that's why i ask on what level, because the framework level doesn't actually fix it for most deployments, including ours

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions