[Home]WikiPatches/URLRewrite

UseModWiki | WikiPatches | RecentChanges | Preferences

My http access log processing strips QueryString?s from its summary output, because generally the interesting request count is for the script itself rather than the actual parameters. Of course, with wikis it is different, since the page is identified in the QueryString? only.

I wanted to use URLs without a QueryString? for normal page reads, while continuing to use QueryString?s for other actions. It was fairly straight-forward with Apache's mod_rewrite and some changes to UseMod.

These rewrite rules assume that /page is a ScriptAlias? (or attached to executing the wiki script in some other way, e.g. with SetHandler? inside <Location /page>).

Another place to modify is the default page on your wiki. On mine it is Home, which is why I send an external redirect for "/" pointing the browser to "/Home". This again helps with my log processing, as "/" does not get accounted for separately (since the wiki script would be returning the contents of the "Home" page anyway).

Finally, I also require all links to be capitalized (even FreeLinks), so I can just look at the first character of the URL to see that the request is for a wiki page. All other content (i.e. static pages, CSS files etc.) use lowercase names.

RewriteEngine On
RewriteRule ^/$ /Home [L,R]
RewriteRule ^/go$ /page [PT,L,QSA]
RewriteRule ^/([A-Z].*)$ /page?$1 [PT,L]

The rules together with mod_perl configuration directives can be found here: ftp://ftp.gw.com/pub/people/kim/patches/usemod/url-rewrite.conf

The support in the wiki script includes two configuration variables:

$PageBase?: points to the base URL for page reads (in my case "/")
$ActionBase?: points to the base URL for all other requests (in my case "/go"; this could just simply be left as "/page")

Leaving either variable empty will use the current default, i.e. auto-detect the name of the script and use it for all requests.

The patch is here: ftp://ftp.gw.com/pub/people/kim/patches/usemod/url-rewrite.diff

-- KimmoSuominen


Below is what I use, the advantage is if a real file (directory, css, images, etc) is requested, the URL isn't rewritten.
/                    =>  /wiki.pl
/MyPage              =>  /wiki.pl?id=MyPage
/MyPage/SubPage      =>  /wiki.pl?id=MyPage/SubPage
/MyPage?action=edit  =>  /wiki.pl?id=MyPage&action=edit
/aDirectory/         =>  /aDirectory/ (if it exists)
/images/myimage.png  =>  /images/myimage.png (if it exists)

/wiki/.htaccess
# Set the default page to the wiki
DirectoryIndex wiki.pl

# URL rewriting for clean URLs
RewriteEngine On

# Set this to the base directory of your wiki (eg www.example.org/wiki/wiki.pl = /wiki/)
RewriteBase /wiki/

# Don't rewrite requests for any files, directories, or symbolic
# links (shortcuts) that exist on the filesystem.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l

# Send requests to wiki.pl, appending the query string part.
RewriteRule ^([^/a-z].*) wiki.pl?id=$1  [QSA,L]
-- AndrewFyfe?

UseModWiki | WikiPatches | RecentChanges | Preferences
Edit text of this page | View other revisions | Search MetaWiki
Last edited December 31, 2006 2:34 pm by 82-69-80-92.dsl.in-addr.zen.co.uk (diff)
Search: