jun
21
2010

Nginx rewrite for Wikka Wiki

I’m posting it here, because I started a few weeks ago working with Nginx (if you don’t know that, you really should), a very powerful and fast webserver (lets leave it for another post), but I faced a problem with redirects for Wikka Wiki, I’m not a beginner on regular expressions or mod_rewrite, but sometimes we get in trouble working on something new.

I haven’t found the solution for my problem (for wordpress, drupal and joomla there are so many) so I resolved it and now I’m posting if somebody can’t do it or just wanna some copy/paste ;)

1
2
3
4
5
6
7
8
9
10
11
12
13
 location ~ ^/wiki {
 	root /path/to/wiki;
 	index wikka.php;
 
 	if (!-e $request_filename) {
 		rewrite ^/wiki/images/(.*)$ /images/$1 break;
		rewrite ^/wiki/templates/(.*)$ /templates/$1 break;
 		rewrite ^/wiki/3rdparty/plugins/freemind/(.*)$ /3rdparty/plugins/freemind/$1 break;
 		rewrite ^/wiki/3rdparty/plugins/wikkaedit/(.*)$ /3rdparty/plugins/wikkaedit/$1 break;
 		rewrite ^/wiki/(.*)$ /wiki/wikka.php?wakka=$1 break;
 		break;
 	}
 }

A brief explanation:

on line 1 we setup where our wiki is located, on our case /wiki, so in line 2 we give full path to where the wiki’s file are located on the filesystem and line 3 we says our index will be wikka.php once Wikka Wiki just redirect index.php to wikka.php (ok I don’t mind why they don’t put the contents of wikka.php on index.php and its over ;) ).

line 5-12 we configure the rewrite rules, on line 5 is the condition what to do when there is no file or symbolic link when a URL is acessed, if its matched the following rules are processed:
line 6-10: rules to ensure that static content like css, js and images won’t be redirected to wikka.php.
line 11: the main rule, that will redirect all URLs to wikka.php so it process and show the output for each wiki page.

I don’t why (I’m new to Nginx) even using the condition if(!-e $request_filename) I need to put the rules to ensure that static content will be reached, if I discover, I update this post, but these rules are working for me under Nginx 0.7.67 and Wikka 1.2-p1

posted in blog by Celso Fernandes

Follow comments via the RSS Feed | Deixe um comentário | Trackback URL

1 Comment to "Nginx rewrite for Wikka Wiki"

  1. Javi wrote:

    My two cents, i added a rewrite condition apart from yours. I wanted to remove the wikka.php form the urls, so added a condition after the one you put to rewrite urls that does not contains wikka.php and converts them wiki php call. This way i can navigate through the wiki using links like http://www.wakkawiki.com/HomePage

    if (!-e $request_filename) {
    rewrite ^/images/(.*)$ /images/$1 break;
    rewrite ^/templates/(.*)$ /templates/$1 break;
    rewrite ^/3rdparty/plugins/freemind/(.*)$ /3rdparty/plugins/freemind/$1 break;
    rewrite ^/3rdparty/plugins/wikkaedit/(.*)$ /3rdparty/plugins/wikkaedit/$1 break;
    rewrite ^/(.*)$ /wikka.php?wakka=$1 break;
    break;
    }

    if ($request_filename !~* wikka.php) {
    rewrite ^(.*)$ wikka.php?wakka=$1 break;
    break;
    }

    Bye !
    Javi

Leave Your Comment