Black Friday: 50% off everythingBlack Friday: 50% off every plan and credit packEnds in --d --h --m
Dashboard

Add a Custom 404 Page to an AI-Built App Properly

A friendly 404 page that returns a 200 status is worse than the default error. Here is how to build one that helps visitors and tells search engines the truth.

Steve Jefferson
Steve Jefferson
Developer Advocate
11 October 20264 min readMake us preferred on Google

To add a custom 404 page to an AI-built app, make a page with a short message and a few useful links, then confirm your server still answers with a 404 status code when it shows it. The design is the easy half. The half that goes wrong in generated apps is the status code, because many single-page apps show a "page not found" screen while quietly returning 200 OK.

Why the status code matters more than the design

A 404 page has two audiences. The visitor reads the page. A crawler or monitoring tool reads the status code. MDN describes a 404 as a response meaning the server cannot find the requested resource, and says it does not tell you whether the absence is temporary or permanent, which is why a permanently removed page should return 410 Gone instead.

If your friendly error screen returns 200, the server is telling everyone the page exists. Google's documentation on HTTP status codes and network errors mentions that when a page returns a success code but its content looks like an error, such as an empty page, Search Console reports a soft 404 error. It also says Google treats all 4xx codes except 429 the same way: the content is considered nonexistent.

The practical result is that a pretty error page with the wrong status code can end up cluttering your index report, while a plain one with the right code does the job.

Why AI-built apps get this wrong

Most AI builders produce a single-page app. In that setup the server returns the same HTML shell for every URL, and JavaScript in the browser decides what to draw. When the route does not match, the code renders a NotFound component, but the server has already sent 200.

You can see this in your own app in under a minute, and the test further down shows how.

What a custom 404 page for an AI-built app needs

Keep it short. A visitor who lands on a dead link wants to get somewhere else, not read a joke.

  1. A plain headline that says the page was not found.

  2. One sentence explaining what likely happened, such as a typo or a page that was moved.

  3. A search box if your app has search, otherwise links to your three most useful pages.

  4. A way to report the broken link, such as a contact link.

  5. The same header and footer as the rest of the site, so people can orient themselves.

Do not redirect every missing URL to the home page. It confuses visitors and, for search engines, looks like the soft 404 problem again.

Return the real status

How you fix the status depends on how your app is served.

  • Server-rendered or framework with routing on the server: set the response status to 404 inside the not-found handler. Frameworks usually have a dedicated not-found file for this.

  • Static hosting: many hosts serve a file named 404.html automatically and attach the 404 status. Check your host's documentation for the exact filename.

  • Pure client-side single-page app: the server cannot know a route is invalid. The common fix is a small server rule or edge function that checks the path against a list of valid routes and returns 404 for anything else.

The two-minute test

Request a URL that cannot exist and read only the status line:

bash
curl -I https://yourdomain.example/this-page-does-not-exist-123

Look at the first line of the output. HTTP/2 404 is correct. HTTP/2 200 means your custom page is a soft 404, however nice it looks. Also test a real page and confirm it still returns 200.

The prompt to paste

text
Add a custom 404 page to this app.
- Show a short "page not found" headline, one sentence of help, a link to the home page and links to our three main pages.
- Keep the normal header and footer.
- The server must respond with HTTP status 404 for unknown URLs, not 200. If this is a client-side app, add a server rule that returns 404 for paths not in the route list.
- Do not redirect unknown URLs to the home page.
- Tell me the exact curl command to verify the status code.

If the agent cannot change server behaviour on your host, ask it to explain the limitation instead of faking the page. Pages that load but mislead are worse than an honest default.

Once the 404 works, check the pages around it. Empty states in an AI-built app covers the screens people hit when a list has nothing in it, which pair naturally with a not-found screen. If you have just moved to your own address, moving an AI-built app to a custom domain lists the redirects to set up so old links do not turn into 404s. And for the wider build, the guide to building an app with AI shows where each of these pieces sits.

A planned outage is a different case, and maintenance mode in an AI-built app should tell visitors and crawlers the page is temporarily unavailable, not missing.

Frequently asked questions

What status code should a custom 404 page return?

  1. If you removed a page on purpose and it will not come back, 410 is more precise, but both tell crawlers the content does not exist.

What is a soft 404?

A page that looks like an error but is served with a success status such as 200. Search Console flags these because the server and the content disagree.

Should I redirect missing pages to the home page?

No. Visitors lose track of what happened, and it can look like a soft 404 to search engines. Show the not-found page and let them choose where to go.

Does a 404 page hurt my site?

An occasional 404 is normal and Google treats it as the content not existing. The problem is broken internal links, so fix those when you find them.

How did this land?

About the author

Steve Jefferson
Steve Jefferson

Developer Advocate

Steve builds something with Swarmz every week and writes up what worked, what broke, and what he'd do differently. Tutorials and hands-on guides are his lane.

Share

Get the next post in your inbox

One email a month. Product updates, engineering posts, and the best of Built with Swarmz.

I agree to receive emails about AI building tips and Swarmz product news. Unsubscribe any time.