Project

General

Profile

HowToRewriteForPMWiki » History » Revision 11

Revision 10 (Anonymous, 2008-10-04 01:25) → Revision 11/13 (Anonymous, 2008-10-04 01:25)

h2. == PMWiki CleanURLs with Lighttpd 


 == 

 Rewriting for PMWiki isn't very difficult at all. 


 h3. 

 === Dedicated vhost 


 === 

 A vhost of wiki.example.com is used in this example. Add this snippet to your lighttpd.conf, after enabling mod_rewrite.  


 <pre> 

  

 {{{ 
 $HTTP["host"] == "wiki.example.com" {    
   index-file.names = ("pmwiki.php") 
   url.rewrite-once = ( 
     "^/([a-zA-Z0-9]+)/([a-zA-Z=?0-9.&:\-_%]+)$" => "/pmwiki.php?n=$1.$2", 
     "^/([a-zA-Z0-9/]+)$" => "/pmwiki.php?n=Category.$1" 
   ) 
 } 
 </pre> 


 }}} 

 I have this code setup to redirect any one-level inquiries (http://wiki.example.com/group) to Category.$1. You can change that easily, and make it $1.$1 or Main.$1, whatever you want. (_blaster8_: (''blaster8'': I have found that to make all of the links with the 'lean' skin sane, the option $1.HomePage $1.!HomePage is the best replacement for Category.$1) 


 Now, change your config variables in config.php to the following: 



 <pre> 

 


 {{{ 
 $EnablePathInfo = 1; 
 $ScriptUrl = "http://wiki.example.com"; 
 $PubDirUrl = "http://wiki.example.com/pub"; 
 </pre> 




 h3. }}} 


 === Subdirectory 


 === 

 To set up a wiki in `http://example.com/wiki/@ `http://example.com/wiki/` instead of @http://wiki.example.com/`, `http://wiki.example.com/`, perform the following steps: 

 Put the following in PMWiki's @config.php@: 

 <pre> 

 `config.php`: 
 {{{ 
 $EnablePathInfo = 1; 
 $ScriptUrl = "http://example.com/wiki"; 
 $PubDirUrl = "http://example.com/wiki/pub"; 
 </pre> 


 }}} 

 Put this in Lighttpd's @lighttpd.conf@: 

 <pre> 

 `lighttpd.conf`: 
 {{{ 
 url.rewrite-once = ( 
     "^/wiki/([a-zA-Z0-9]+)/([a-zA-Z=?0-9.&:\-_%]+)$" => "/wiki/pmwiki.php?n=$1.$2", 
     "^/wiki/([a-zA-Z0-9/]+)$" => "/wiki/pmwiki.php?n=Category.$1" 
 ) 
 </pre> 


 }}} 

 Create a file called @index.php@ `index.php` with the following contents in the same directory as @pmwiki.php@: 


 <pre> 

 `pmwiki.php`: 

 {{{ 
 <?php require("pmwiki.php"); ?> 
 </pre> 



 h3. }}} 

 === `url.rewrite` rules 


 === 

 The regular expressions used above can also be rewritten to a single rule: 

 <pre> 

 
 {{{ 
 url.rewrite-once = ("^/([A-Z].*)" => "/pmwiki.php?n=$1") 
 </pre> 

 }}} 
 This lets the @pmwiki.php@ `pmwiki.php` script handle any URL that starts with a capital letter. If your wiki conforms to the _de facto_ ''de facto'' pmwiki standards, this should be enough.