]> sipb.mit.edu Git - ikiwiki.git/blob - doc/bugs/trouble_with_base_in_search.mdwn
16e4e74681a7af8e3abb866649480c4149421b5d
[ikiwiki.git] / doc / bugs / trouble_with_base_in_search.mdwn
1 For security reasons, one of the sites I'm in charge of uses a Reverse Proxy to grab the content from another machine behind our firewall.
2 Let's call the out-facing machine Alfred and the one behind the firewall Betty.
3
4 For the static pages, everything is fine.  However, when trying to use the search, all the links break.
5 This is because, when Alfred passes the search query on to Betty, the search result has a "base" tag which points to Betty, and all the links to the "found" pages are relative.
6 So we have
7
8     <base href="Betty.example.com"/>
9     ...
10     <a href="./path/to/found/page/">path/to/found/page</a>
11
12 This breaks things for anyone on Alfred, because Betty is behind a firewall and they can't get there.
13
14 What would be better is if it were possible to have a "base" which didn't reference the hostname, and for the "found" links not to be relative.
15 Something like this:
16
17     <base href="/"/>
18     ...
19     <a href="/path/to/found/page/">path/to/found/page</a>
20
21 The workaround I've come up with is this.
22
23 1. Set the "url" in the config to '&nbsp;' (a single space).  It can't be empty because too many things complain if it is.
24 2. Patch the search plugin so that it saves an absolute URL rather than a relative one.
25
26 Here's a patch:
27
28     diff --git a/IkiWiki/Plugin/search.pm b/IkiWiki/Plugin/search.pm
29     index 3f0b7c9..26c4d46 100644
30     --- a/IkiWiki/Plugin/search.pm
31     +++ b/IkiWiki/Plugin/search.pm
32     @@ -113,7 +113,7 @@ sub indexhtml (@) {
33             }
34             $sample=~s/\n/ /g;
35     
36     -       my $url=urlto($params{destpage}, "");
37     +       my $url=urlto($params{destpage}, undef);
38             if (defined $pagestate{$params{page}}{meta}{permalink}) {
39                     $url=$pagestate{$params{page}}{meta}{permalink}
40             }
41
42 It works for me, but it has the odd side-effect of prefixing links with a space.  Fortunately that doesn't seem to break browsers.
43 And I'm sure someone else could come up with something better and more general.