# How do I return 404? 🛑

**URL:** https://community.weweb.io/t/how-do-i-return-404/10111
**Category:** How do I?
**Created:** [August 6, 2024, 10:26am UTC](https://community.weweb.io/t/how-do-i-return-404/10111 "2024-08-06T10:26:18Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![davhad](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/davhad/32/9664_2.png) [@davhad](https://community.weweb.io/u/davhad)
#### Post date: [August 6, 2024, 10:26am UTC](https://community.weweb.io/t/how-do-i-return-404/10111/1 "2024-08-06T10:26:18Z")

</div>

With a page that shows data based on a slug, if the slug has no match in the database, I’d like to return a 404 error to the browser.

Now I’m redirecting to a page with an error message via a Navigate To action but that’s not the desired goal. Anyone has experience with this with a workaround?

---

<div class="post-metadata">

### Author: ![Joyce](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/joyce/32/13232_2.png) [@Joyce](https://community.weweb.io/u/Joyce)
#### Post date: [August 6, 2024, 11:08am UTC](https://community.weweb.io/t/how-do-i-return-404/10111/2 "2024-08-06T11:08:49Z")

</div>

Hi @davhad 👋

Does this help: [Create 404 page | WeWeb Documentation](https://docs.weweb.io/pages/404-page.html)

---

<div class="post-metadata">

### Author: ![davhad](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/davhad/32/9664_2.png) [@davhad](https://community.weweb.io/u/davhad)
#### Post date: [August 6, 2024, 11:23am UTC](https://community.weweb.io/t/how-do-i-return-404/10111/3 "2024-08-06T11:23:26Z")

</div>

Hey @Joyce that is what I already have (had stumbled on that doc and applied it).

But if you redirect users to a 404 page using the navigate to action, that’s not returning a 404 error to the browser. Or am I wrong?

I’m looking for a way to return a 404 error.

---

<div class="post-metadata">

### Author: ![Joyce](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/joyce/32/13232_2.png) [@Joyce](https://community.weweb.io/u/Joyce)
#### Post date: [August 6, 2024, 11:24am UTC](https://community.weweb.io/t/how-do-i-return-404/10111/4 "2024-08-06T11:24:29Z")

</div>

You don’t need to use the navigate to action. The user will be automatically redirected to the 404 page if the slug doesn’t exist

---

<div class="post-metadata">

### Author: ![davhad](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/davhad/32/9664_2.png) [@davhad](https://community.weweb.io/u/davhad)
#### Post date: [August 6, 2024, 11:29am UTC](https://community.weweb.io/t/how-do-i-return-404/10111/5 "2024-08-06T11:29:44Z")

</div>

Can you help me understand how Weweb deals with that under the hood?

In this app, if the slug doesn’t exist, that means that the onpageload collection query to get an item based on the slug (filter: item.slug = page slug param) will return 0 items (length=0).

Right now, when this happens, all in-page components bound to the item’s properties are showing as undefined and the page is rendering normally with lots of undefined’s everywhere.

---

<div class="post-metadata">

### Author: ![Broberto](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/broberto/32/5918_2.png) [@Broberto](https://community.weweb.io/u/Broberto)
#### Post date: [August 6, 2024, 12:08pm UTC](https://community.weweb.io/t/how-do-i-return-404/10111/6 "2024-08-06T12:08:21Z")

</div>

> [@Joyce](#):
>
> You don’t need to use the navigate to action. The user will be automatically redirected to the 404 page if the slug doesn’t exist

He wants to explicitly throw a 404 if something happens, e.g if the parameter is not present/is not found in the DB, he would like to throw a 404 error and show the view. This is currently not possible as far as I understand, as it would require routing middleware? Only static collections work like this. @davhad

---

<div class="post-metadata">

### Author: ![davhad](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/davhad/32/9664_2.png) [@davhad](https://community.weweb.io/u/davhad)
#### Post date: [August 6, 2024, 12:14pm UTC](https://community.weweb.io/t/how-do-i-return-404/10111/7 "2024-08-06T12:14:17Z")

</div>

Yes precisely @Broberto

---

<div class="post-metadata">

### Author: ![Jane](https://avatars.discourse-cdn.com/v4/letter/j/ecb155/32.png) [@Jane](https://community.weweb.io/u/Jane)
#### Post date: [August 12, 2024, 11:28pm UTC](https://community.weweb.io/t/how-do-i-return-404/10111/8 "2024-08-12T23:28:42Z")

</div>

You could have a page workflow that navigates the user to the 404 page is the returned items are empty. It may take a half a second to get the backend API response though. Any reason that wouldn’t work?

---

<div class="post-metadata">

### Author: ![Broberto](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/broberto/32/5918_2.png) [@Broberto](https://community.weweb.io/u/Broberto)
#### Post date: [August 13, 2024, 4:00am UTC](https://community.weweb.io/t/how-do-i-return-404/10111/9 "2024-08-13T04:00:45Z")

</div>

Its not a best practice

---

<div class="post-metadata">

### Author: ![davhad](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/davhad/32/9664_2.png) [@davhad](https://community.weweb.io/u/davhad)
#### Post date: [August 13, 2024, 6:56am UTC](https://community.weweb.io/t/how-do-i-return-404/10111/10 "2024-08-13T06:56:41Z")

</div>

Hey Jane, thanks. That’s what I have in place which I’m trying to improve upon 🙂

---

<div class="post-metadata">

### Author: ![Broberto](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/broberto/32/5918_2.png) [@Broberto](https://community.weweb.io/u/Broberto)
#### Post date: [August 13, 2024, 7:04am UTC](https://community.weweb.io/t/how-do-i-return-404/10111/11 "2024-08-13T07:04:58Z")

</div>

The issue with this approach is mostly that you get redirected, which doesn’t mark the page itself as a 404 (for example for Google Search, or other crawler bots) but it simply redirects you to a 404. The URL will return 200 - OK and then bring you to a 404 - Not Found

---

<div class="post-metadata">

### Author: ![davhad](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/davhad/32/9664_2.png) [@davhad](https://community.weweb.io/u/davhad)
#### Post date: [August 13, 2024, 7:07am UTC](https://community.weweb.io/t/how-do-i-return-404/10111/12 "2024-08-13T07:07:29Z")

</div>

Yes. And I agree that’s a huge issue!

---

<div class="post-metadata">

### Author: ![Joyce](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/joyce/32/13232_2.png) [@Joyce](https://community.weweb.io/u/Joyce)
#### Post date: [August 13, 2024, 7:06pm UTC](https://community.weweb.io/t/how-do-i-return-404/10111/13 "2024-08-13T19:06:28Z")

</div>

Hey @davhad 👋 I’m sorry I don’t have the answer of how it works under the hood. Let me try to get a dev on the topic to help you with this 🙂

---

<div class="post-metadata">

### Author: ![Marc](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/marc/32/30_2.png) [@Marc](https://community.weweb.io/u/Marc)
#### Post date: [August 14, 2024, 7:36am UTC](https://community.weweb.io/t/how-do-i-return-404/10111/15 "2024-08-14T07:36:47Z")

</div>

Hi, it’s not possible to force a 404 redirection for now.

If I understand correctly, you want a page like this to return a 404 error ?

```auto
https://www.mysite.com/products/non-existing-product/

```

The WeWeb server that returns this page has no way of knowing if this product exists or not in your data so it will just return the page and let you do the logic.  
If the product does not exists then you can show an error message or redirect to the 404 page but there will not be a 404 HTTP code.  
Even if you manage to redirect to the 404 page with a 404 HTTP code, the origin page (/non-existing-product/) has already returned a 200 HTTP code and this is what Google will index.

As of today, you cannot really solve your issue. In the future we may add a feature to return 404 when a product does not exist, but it is not planned for now.

---

<div class="post-metadata">

### Author: ![davhad](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/davhad/32/9664_2.png) [@davhad](https://community.weweb.io/u/davhad)
#### Post date: [August 15, 2024, 9:35am UTC](https://community.weweb.io/t/how-do-i-return-404/10111/16 "2024-08-15T09:35:50Z")

</div>

Thanks @Joyce and @Marc. With this alley being a dead end, off to exploring other ways to solve this issue 😅

---

<div class="post-metadata">

### Author: ![davhad](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/davhad/32/9664_2.png) [@davhad](https://community.weweb.io/u/davhad)
#### Post date: [August 15, 2024, 9:49am UTC](https://community.weweb.io/t/how-do-i-return-404/10111/17 "2024-08-15T09:49:27Z")

</div>

So it turns out eventhough technically a redirect to an error page (with http 200) doesn’t produce a 404, google as I have just come to learn has a special classification that called a “soft 404”. Just sharing in case it’s helpful to anyone.

 ![Screenshot 2024-08-15 at 11.40.33](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/7/71a6d90f1c408b44b0a8315cf5c6be8eaff32090.png)
