aboutsummaryrefslogtreecommitdiff
path: root/doc/forum/missing_pages_redirected_to_search-SOLVED/comment_2_bc0291b1afc2e9b4a853c168d3adfd78._comment
blob: d170ab42102a42e95f2e392ba95c35da4b8baceb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
[[!comment format=mdwn
 username="https://launchpad.net/~eliasson"
 nickname="eliasson"
 subject="comment 2"
 date="2016-01-31T20:07:52Z"
 content="""
Using Apache 2.4.10 (Debian 8's package) I solved it the following way:

1. In the Apache site configuration, set `ErrorDocument 404` to the ikiwiki.cgi URL path.
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.

[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.

<pre>
<code>
diff --git a/IkiWiki/Plugin/404.pm b/IkiWiki/Plugin/404.pm
index 42cfa9e..a12fd40 100644
--- a/IkiWiki/Plugin/404.pm
+++ b/IkiWiki/Plugin/404.pm
@@ -74,7 +74,9 @@ sub cgi ($) {
 		my $page = cgi_page_from_404(
 			Encode::decode_utf8($ENV{REDIRECT_URL}),
 			$config{url}, $config{usedirs});
-		IkiWiki::Plugin::goto::cgi_goto($cgi, $page);
+
+		$ENV{QUERY_STRING}=\"P=$page\";
+		IkiWiki::Plugin::search::search($cgi);
 	}
 }
 
diff --git a/IkiWiki/Plugin/search.pm b/IkiWiki/Plugin/search.pm
index 24b16fe..24d7b3c 100644
--- a/IkiWiki/Plugin/search.pm
+++ b/IkiWiki/Plugin/search.pm
@@ -183,24 +183,31 @@ sub delete (@) {
 	}
 }
 
+sub search($) {
+	my $cgi=shift;
+
+	if ($config{google_search}) {
+		print $cgi->redirect(\"https://www.google.com/search?sitesearch=$config{url}&q=\".$cgi->param('P'));
+		exit 0;
+	}
+	else {
+		# only works for GET requests
+		chdir(\"$config{wikistatedir}/xapian\") || error(\"chdir: $!\");
+		$ENV{OMEGA_CONFIG_FILE}=\"./omega.conf\";
+		$ENV{CGIURL}=IkiWiki::cgiurl();
+		IkiWiki::loadindex();
+		$ENV{HELPLINK}=htmllink(\"\", \"\", \"ikiwiki/searching\",
+					noimageinline => 1, linktext => \"Help\");
+
+		exec($config{omega_cgi}) || error(\"$config{omega_cgi} failed: $!\");
+	}
+}
+
 sub cgi ($) {
 	my $cgi=shift;
 
 	if (defined $cgi->param('P')) {
-		if ($config{google_search}) {
-			print $cgi->redirect(\"https://www.google.com/search?sitesearch=$config{url}&q=\".$cgi->param('P'));
-			exit 0;
-		}
-		else {
-			# only works for GET requests
-			chdir(\"$config{wikistatedir}/xapian\") || error(\"chdir: $!\");
-			$ENV{OMEGA_CONFIG_FILE}=\"./omega.conf\";
-			$ENV{CGIURL}=IkiWiki::cgiurl();
-			IkiWiki::loadindex();
-			$ENV{HELPLINK}=htmllink(\"\", \"\", \"ikiwiki/searching\",
-				noimageinline => 1, linktext => \"Help\");
-			exec($config{omega_cgi}) || error(\"$config{omega_cgi} failed: $!\");
-		}
+		search($cgi);
 	}
 }
 
</code>
</pre>
"""]]