Join the Webstudio community

Updated 4 months ago

Can you redirect all 404 Status Code Pages to a Custom 404 Page?

At a glance
I have a page with dynamic path /blog/:url_slug. I noticed that Webstudio will show the dynamic page even if the URL does not exist. For example if I put /blog/123456 (a page that does not exist), Webstudio will still show it. Since there is no data to pull from dynamic resource the heading and description appear empty and "Content Embed" component shows "Open the Settings Panel to Insert HTML Code" (in the live site).

To try to fix this I added the following expression in the Status code !Posts.data.records[0].fields[5].values[0].value ? 404 : 200. At least with this I fixed the issue with Google crawling a page that does not exist.

The problem is that Webstudio is still showing the empty dynamic page in the live site. Is there a way to redirect any 404 status code pages to a custom 404 page?
3
O
J
L
15 comments
@John Siciliano turns out we didn't handle this case ourselves, e.g. https://webstudio.is/blog/webstudios-architecture-an-overview1
we talked about this a while ago in cms launch. IIRC there was discussion about auto forwarding statuses
dm'd you the DMs we had about this πŸ™‚
I'm seeing the exact same thing in my sites.
I think a good solution for this is to have a default 404 page (something like the option Make "Page" the home page checkmark in page settings) that will automatically redirect any status 404 to that custom page.
We have a plan for this, @TrySound is creating an issue
Same way you can conditionally render 404 error on the page
!Posts.data.records[0].fields[5].values[0].value ? 404 : 200
What's missing is after you created a 404 page is to forward rendering of that 404 page under that wrong url. So URL stays, but content is 404
we are even rendering a 404 status code on our blog but we aren't forwarding the rendering of the content to 404
Attachment
image.png
Hey guys ! Sorry to bump this thread 😬

Any news on this ? If not, is there a workaround to prevent empty cms pages from showing ? (And show 404 instead)
Hey no movement but you can just make two sections on your page. One section has all your CMS content and another section has 404. Then on each one you bind a condition to the show field. Some like myPostId ? true : false on the content section and myPostId ? false : true

Ie show 404 when the id is not found and show the content when the id is found
Hey John !

Yup, good idea. That will totally do for !

Thanks πŸ™‚
what I do is that if the content i get is empty I redirect to a 404, I do lose the url on top because of this.
Current approach is conditionally render 404 error instead of content.
Add a reply
Sign up and join the conversation on Discord