]> sipb.mit.edu Git - ikiwiki.git/blob - doc/forum/missing_pages_redirected_to_search-SOLVED/comment_1_aa03c337b31d7acb95761eb51caab1ef._comment
Added a comment: For lighttpd with mod_magnet
[ikiwiki.git] / doc / forum / missing_pages_redirected_to_search-SOLVED / comment_1_aa03c337b31d7acb95761eb51caab1ef._comment
1 [[!comment format=mdwn
2  username="mathdesc"
3  subject="For lighttpd with mod_magnet"
4  date="2012-08-18T18:27:32Z"
5  content="""
6 Same can be done for lighttpd via a lua script (said rewrite.lua) using *mod_magnet* than need to be installed and
7 called in your conf like this :
8
9 <pre>
10 # error-handler for status 404                                         
11 $HTTP[\"url\"] =~ \"^/mysite/\" { 
12 magnet.attract-physical-path-to = ( server.document-root + \"/rewrite.lua\" )
13 }
14 </pre>
15
16 Ref :
17 [[mod_magnet docs|http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs_ModMagnet]]
18
19
20
21 <pre>
22
23   function removePrefix(str, prefix)    
24         return str:sub(1,#prefix+1) == prefix..\"/\" and str:sub(#prefix+2)
25   end
26
27
28
29    attr = lighty.stat(lighty.env[\"physical.path\"])
30    local prefix = '/mysite'
31    if (not attr) then
32         -- we couldn't stat() the file 
33         -- let's generate a xapian query with it
34         new_uri =removePrefix(lighty.env[\"uri.path\"], prefix)
35         print (\"page not found : \" .. new_uri .. \" asking xapian\")
36         lighty.env[\"uri.path\"] = \"/mysite/ikiwiki.cgi\"    
37         lighty.env[\"uri.query\"] = \"P=\" .. new_uri  
38         lighty.env[\"physical.rel-path\"] = lighty.env[\"uri.path\"]
39         lighty.env[\"physical.path\"] = lighty.env[\"physical.doc-root\"] .. lighty.env[\"physical.rel-path\"]
40     end
41 </pre>   
42
43 Hope this is useful to you :)
44 """]]