Graham Dumpleton
grahamd at dscpl.com.au
Fri Nov 11 22:47:39 EST 2005
On 12/11/2005, at 8:29 AM, Brandon N wrote: > Ive had some good luck coming to terms with Apache/mod_python/ > Vampire but I've run into a snag. > > How does one setup an "ErrorDocument 404 /404.py" with a Vampire/ > mod_python file? All my attempts (basically the first tutorial > handler_html etc) are met with: > The requested URL /something.html was not found on this server. > > Additionally, a 403 Forbidden error was encountered while trying to > use an ErrorDocument to handle the request. > > Any ideas? Vampire imposes the ideal that URLs should never use a .py extension, thereby ensuring that the fact that Python is being used isn't obvious. This extends to internally redirected URLs such as that specified for ErrorDocument. Thus, for starters don't specify "/404.py" as the target URL for ErrorDocument. For an error document call "404.py" containing: from mod_python import apache def handler(req): req.status = apache.HTTP_NOT_FOUND req.content_type = 'text/html' req.write("<html><body><p>NOT FOUND</p></body></html>") return apache.DONE Use an Apache configuration of: Options -MultiViews ErrorDocument 404 /~grahamd/vampire/404 Ie., no extension on ErrorDocument URL, so handler function is called "handler()". Adjust actual location component of URL as appropriate. Note that in this case it is extra important that the Apache MultiViews options is disabled. It is recommended that this be disabled whenever using Vampire anyway, or at least when you want URLs with no extension. Alternatively, instead of calling it "handler()", call it "handler_html()" and use: ErrorDocument 404 /~grahamd/vampire/404.html Presuming that is that it returns HTML, else it wouldn't really make sense to use that extension. BTW, have explicitly set req.status, but this is probably not actually required as Apache knows it is a 404 error already and has therefore set it. I have returned apache.DONE instead of apache.OK just to ensure no extra phases are somehow executed after the handler is executed to serve up the error document. Anyway, see how that goes. Graham
|