Forum OpenACS Q&A: Error pages and Host Node Mapping

Collapse
Posted by Ryan Gallimore on
I have a host-node mapped site with a theme. There doesn't seem to be a way to create theme-specific templated error pages for 404/500 etc errors.

Has anyone been able to set this up?

Collapse
Posted by Ryan Gallimore on
In the config file:

ns_section "ns/server/${server}/redirects"
ns_param 404 "global/file-not-found.adp"

You must use an ADP file. You cannot use a tcl/adp pair so, any tcl code must be embedded in the ADP.

/www/global/file-not-found.adp:


<%
rp_internal_redirect /www/global/404
ns_adp_abort
%>

Note in order to use the templating system, we have to invoke the request processor. We call ns_adp_abort to avoid a tcl exception about closing the connection before the adp buffer is flushed.

/www/global/404.adp:


<master>

<h1>Sorry, page not found</h1>

The master tag will template the page contextually, so if a file is not found in the main site, the main site theme will be used, if a file is not found in a subsite (or host node map), the subsite theme will be used.

The only remaining issue is that with this solution, a 404 response code is not actually returned.

Collapse
Posted by Torben Brosten on
Example 404 error return ( '<' removed from tags so they aren't blocked/rendered ).

< %
ns_return 404 text/html {<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"
"http://www.w3.org/TR/REC-html40/strict.dtd">;
html>
head>
title>http 404 page not found/title>
/head>
body>
p>page not found (http 404 error)/p>

p>The page you requested is not available. /p>
p>Try from the a href="/">Home page/a>./p>

/body>/html>
}
% >

Collapse
Posted by Ryan Gallimore on
This is fine for a simple error page but it can't be templated with themes.