]> sipb.mit.edu Git - ikiwiki.git/blob - doc/bugs/404_plugin_and_lighttpd.mdwn
probably a markdown issue
[ikiwiki.git] / doc / bugs / 404_plugin_and_lighttpd.mdwn
1 Lighttpd apparently sets REDIRECT_STATUS=200 for the server.error-handler-404 page. This breaks the [[plugins/404]] plugin which checks this variable for 404 before processing the URI. It also doesn't seem to set REDIRECT_URL.
2
3 > For what it's worth, the first half is <http://redmine.lighttpd.net/issues/1828>.
4 > One workaround would be to make this script your 404 handler:
5 >
6 >     #!/bin/sh
7 >     REDIRECT_STATUS=404; export REDIRECT_STATUS
8 >     REDIRECT_URL="$SERVER_NAME$REQUEST_URI"; export REDIRECT_URL
9 >     exec /path/to/your/ikiwiki.cgi "$@"
10 >
11 > --[[smcv]]
12
13 I was able to fix my server to check the REQUEST_URI for ikiwiki.cgi and to continue processing if it was not found, passing $ENV{SEVER_NAME} . $ENV{REQUEST_URI} as the first parameter to cgi_page_from_404. However, my perl is terrible and I just made it work rather than figuring out exactly what to do to get it to work on both lighttpd and apache.
14
15 This is with lighttpd 1.4.19 on Debian.
16
17 > /cgi-bin/ikiwiki.cgi?do=goto also provides redirection in the same way,
18 > if that's any help? You might need to set the lighttpd 404 handler to
19 > that, then compose REDIRECT_URL from other variables if necessary.
20 >
21 > I originally wrote the plugin for Apache; [[weakish]] contributed the
22 > lighttpd docs and might know more about how to make it work there.
23 > --[[smcv]]
24
25 >> As I said, I got it working for me, but somebody who knows perl should probably look at it with the aim of making it work for everyone.
26 >> I considered having lighttpd construct a proper url for the 404 redirect itself, but I don't know if it can do something like that or not.
27 >> For what it's worth, here's the change I made to the module:
28
29     sub cgi ($) {
30             my $cgi=shift;
31             if ($ENV{REQUEST_URI} !~ /ikiwiki\.cgi/) {
32                     my $page = cgi_page_from_404(
33                             Encode::decode_utf8($ENV{SERVER_NAME} . $ENV{REQUEST_URI}),
34                             $config{url}, $config{usedirs});
35                     IkiWiki::Plugin::goto::cgi_goto($cgi, $page);
36             }
37     
38     #       if (exists $ENV{REDIRECT_STATUS} &&
39     #           $ENV{REDIRECT_STATUS} eq '404') {
40     #               my $page = cgi_page_from_404(
41     #                       Encode::decode_utf8($ENV{REDIRECT_URL}),
42     #                       $config{url}, $config{usedirs});
43     #               IkiWiki::Plugin::goto::cgi_goto($cgi, $page);
44     #       }
45     }