Blog-Core framework

Fork me on GitHub

Custom 404 pages

SWI-Prolog does not easily allow to respond with custom 404 pages. There is some support for this in version 7.3.17 but that does not work with a custom template engine and requires the page to be coded as html//1 DCG.

This can be worked around with a little help from Nginx (see also: running with Nginx). Firsty, write a 404 handler in Blog-Core that will produce the page. It can look like this:

:- route_get('404', get_404_page).

get_404_page:-
    bc_view_send(views/'404', _{
        title: 'Not found - 404',
        description: 'The page was not found.'
    }).

The view file views/404.html must exist and contain the content you want to show on it.

Secondly, Nginx needs two extra options besides the standard reverse proxy configuration:

error_page 404 /404;
proxy_intercept_errors on;

The first line defines custom URL for error pages and the second one makes the reverse proxy use that URL for proxied app errors too. This configuration goes into the server block. It's not an issue that the custom 404 page is served through the proxy itself.