picocms/Pico

404 and around

Closed this issue · 4 comments

If I create a plugin that serves a page when I request site/fakepage, for example using onPageRendering with $twigTemplate = 'fakepage.twig', Pico still considers this as 404 content. On the user side, everything works fine, but is404Content() returns true (similarly, on404ContentLoaded(&$rawContent) is also triggered). Is there a way to work around this? For instance, if I want to log all the requests that result in a 404, calls to site/fakepage would also be logged as 404s, but they shouldn't be.

Another question about 404 behavior: If I create a 404.md page and point to mysite/404, Pico serves the 404 page, but with a 200 OK response, because the page actually exists. Is it an expected behavior? A better practice would be to only allow a _404.md file, which is not accessible directly but is used by Pico to serve a 404 message when there is a bad request. This approach, like before, avoids false positives when plugins check for is404Content().

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in two days if no further activity occurs. Thank you for your contributions! 👍

If I create a plugin that serves a page when I request site/fakepage, for example using onPageRendering with $twigTemplate = 'fakepage.twig', Pico still considers this as 404 content. […] Is there a way to work around this?

I'm afraid there isn't. There were plans for Pico 4.0 to fix that (by adding "virtual pages"), but that never materialized. Since your plugin is taking control anyway, you don't really have to care about is404Content() yielding true; the only effect it has is that you have to change the HTTP status code back to 200 OK.

Another question about 404 behavior: If I create a 404.md page and point to mysite/404, Pico serves the 404 page, but with a 200 OK response, because the page actually exists. Is it an expected behavior?

No, 404.md files are considered hidden and should therefore follow the is404Content path. Please check again (because the code looks right to me) and if Pico truly responds with 200 OK (check that no plugin is changing the status code!) please open a separate issue. However, as a disclaimer, since Pico's development has stopped, it's unlikely that it will be fixed.

I'm afraid there isn't. There were plans for Pico 4.0 to fix that (by adding "virtual pages"), but that never materialized.

Ok, thanks.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in two days if no further activity occurs. Thank you for your contributions! 👍