]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - doc/forum/missing_pages_redirected_to_search-SOLVED/comment_2_bc0291b1afc2e9b4a853c168d3adfd78._comment
Added a comment
[git.ikiwiki.info.git] / doc / forum / missing_pages_redirected_to_search-SOLVED / comment_2_bc0291b1afc2e9b4a853c168d3adfd78._comment
1 [[!comment format=mdwn
2  username="https://launchpad.net/~eliasson"
3  nickname="eliasson"
4  subject="comment 2"
5  date="2016-01-31T20:07:52Z"
6  content="""
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.
14 <pre>
15 <code>
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);
25 +
26 +               $ENV{QUERY_STRING}=\"P=$page\";
27 +               IkiWiki::Plugin::search::search($cgi);
28         }
29  }
30  
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 (@) {
36         }
37  }
38  
39 +sub search($) {
40 +       my $cgi=shift;
41 +
42 +       if ($config{google_search}) {
43 +               print $cgi->redirect(\"https://www.google.com/search?sitesearch=$config{url}&q=\".$cgi->param('P'));
44 +               exit 0;
45 +       }
46 +       else {
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\");
54 +
55 +               exec($config{omega_cgi}) || error(\"$config{omega_cgi} failed: $!\");
56 +       }
57 +}
58 +
59  sub cgi ($) {
60         my $cgi=shift;
61  
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'));
65 -                       exit 0;
66 -               }
67 -               else {
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: $!\");
76 -               }
77 +               search($cgi);
78         }
79  }
80  
81 </code>
82 </pre>
83 """]]