! I can handle this on the 404 page via a script in theme HTML…
I have the 404 page reload the browser window to the “missing” url which will hit the server-side. It works! Only downside I see is the redirect is noticeable and you get taken out of the app for any real 404s (losing the sidebar/header).
<script type="text/discourse-plugin" version="0.8">
api.onPageChange((url, title) => {
const router = api.container.lookup('service:router');
var is404 = document.getElementsByClassName("page-not-found");
if (is404.length) {
const params = new URLSearchParams(router.currentRoute.queryParams).toString();
let q = "";
if (params){ q = "?"+params; }
window.location.replace(window.location.origin + url + q);
}
});
</script>