2 username="https://launchpad.net/~eliasson"
5 date="2016-01-31T20:07:52Z"
7 Using Apache 2.4.10 (Debian 8's package) I solved it the following way:
9 1. In the Apache site configuration, set `ErrorDocument 404` to the ikiwiki.cgi URL path.
10 2. Apply the following patch to the plugins search and 404. The easiest and probably cleanest way is to copy the plugins to your `$libdir/IkiWiki/Plugins` and edit them there. It works with xapian omega search but wouldn't work with google, since the *P* CGI parameter is not set (instead, omega uses the `QUERY_STRING` environment variable). Perhaps one day I'll make this a proper patch and submit as a pull request.
12 [Apache 2.4.13 adds support](https://httpd.apache.org/docs/2.4/mod/core.html#errordocument) for dynamic strings in `ErrorDocument`s, so you could do something similar to the solution for Nginx above. Until that is packaged in your stable Linux distro of choice, this hack can be used.
16 diff --git a/IkiWiki/Plugin/404.pm b/IkiWiki/Plugin/404.pm
17 index 42cfa9e..a12fd40 100644
18 --- a/IkiWiki/Plugin/404.pm
19 +++ b/IkiWiki/Plugin/404.pm
20 @@ -74,7 +74,9 @@ sub cgi ($) {
21 my $page = cgi_page_from_404(
22 Encode::decode_utf8($ENV{REDIRECT_URL}),
23 $config{url}, $config{usedirs});
24 - IkiWiki::Plugin::goto::cgi_goto($cgi, $page);
26 + $ENV{QUERY_STRING}=\"P=$page\";
27 + IkiWiki::Plugin::search::search($cgi);
31 diff --git a/IkiWiki/Plugin/search.pm b/IkiWiki/Plugin/search.pm
32 index 24b16fe..24d7b3c 100644
33 --- a/IkiWiki/Plugin/search.pm
34 +++ b/IkiWiki/Plugin/search.pm
35 @@ -183,24 +183,31 @@ sub delete (@) {
42 + if ($config{google_search}) {
43 + print $cgi->redirect(\"https://www.google.com/search?sitesearch=$config{url}&q=\".$cgi->param('P'));
47 + # only works for GET requests
48 + chdir(\"$config{wikistatedir}/xapian\") || error(\"chdir: $!\");
49 + $ENV{OMEGA_CONFIG_FILE}=\"./omega.conf\";
50 + $ENV{CGIURL}=IkiWiki::cgiurl();
51 + IkiWiki::loadindex();
52 + $ENV{HELPLINK}=htmllink(\"\", \"\", \"ikiwiki/searching\",
53 + noimageinline => 1, linktext => \"Help\");
55 + exec($config{omega_cgi}) || error(\"$config{omega_cgi} failed: $!\");
62 if (defined $cgi->param('P')) {
63 - if ($config{google_search}) {
64 - print $cgi->redirect(\"https://www.google.com/search?sitesearch=$config{url}&q=\".$cgi->param('P'));
68 - # only works for GET requests
69 - chdir(\"$config{wikistatedir}/xapian\") || error(\"chdir: $!\");
70 - $ENV{OMEGA_CONFIG_FILE}=\"./omega.conf\";
71 - $ENV{CGIURL}=IkiWiki::cgiurl();
72 - IkiWiki::loadindex();
73 - $ENV{HELPLINK}=htmllink(\"\", \"\", \"ikiwiki/searching\",
74 - noimageinline => 1, linktext => \"Help\");
75 - exec($config{omega_cgi}) || error(\"$config{omega_cgi} failed: $!\");