Here's how to make clean URLs for MoinMoin with the help of Apache's mod_rewrite and mod_proxy. The idea is that the clean URLs are rewritten to regular moin.cgi URLs using mod_rewrite, and then hidden from the user by feeding the rewritten URL back into Apache for processing using mod_proxy.

In the virtual directory section for your server, add these lines:

RewriteEngine on
RewriteCond %{REQUEST_URI} ^/[ABCDEFGHIJKLMNOPQRSTUVWXYZ] 
RewriteRule ^/(.*) moin.cgi/$1 [P]

This applies the rewrite rule to any URL off the root that starts with a capital letter. This is not ideal, but if you are using standard WikiNames it works fine... the [P] directive means feed the rewritten URL back into Apache for processing using mod_proxy.

Our moin.cgi script is in the root directory of our VirtualHost. You may need to change the rewrite rule

You will need to have mod_rewrite and mod_proxy enabled in your httpd.conf file. Here's some relevant links:

To make this work we also had to change Apache's configuration to allow use of mod_rewrite for our VirtualHost, since the server was configured to deny all use of mod_proxy by default. You may or may not have to do this.

SeaPIG's virtual directory listing looks like this:

<VirtualHost 65.102.170.153>
ServerAdmin webmaster@www.seapig.org
DocumentRoot /home/seapig/www
ServerName www.seapig.org
ServerAlias  *.seapig.org
ErrorLog logs/seapig-error_log
TransferLog logs/seapig-access_log
UserDir www
ProxyRequests on
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/[ABCDEFGHIJKLMNOPQRSTUVWXYZ] 
RewriteRule ^/(.*) moin.cgi/$1 [P]
<Directory "/home/seapig/www">
    AllowOverride None
    Options MultiViews Indexes SymLinksIfOwnerMatch ExecCGI All
    Order allow,deny
    Allow from all
</Directory>
</VirtualHost>


However, it turns out that a rewrite rule is not quite enough, we do need a small refactoring of one method in MoinMoin.

Here's the problem. The rewrite rule (without the user knowing) rewrites all the URLs of the form

http://www.seapig.org/FrontPage

to URLs like

http://www.seapig.org/cgi-bin/moin.cgi/FrontPage

But. When MoinMoin generates html, it generates links for each page that look like

moin.cgi/FrontPage

So, we changed a method in MoinMoin/webapi/cgiMoin.py called getScriptname to only return the scriptname if a configuration variable is equal to 1. Here's the patch:

? moin/MoinMoin/processor/__init__.pyc
Index: moin/MoinMoin/config.py
===================================================================
RCS file: /cvsroot/moin/MoinMoin/config.py,v
retrieving revision 1.64
diff -r1.64 config.py
124a125
>     'use_scriptname': 1,
Index: moin/MoinMoin/webapi/cgiMoin.py
===================================================================
RCS file: /cvsroot/moin/MoinMoin/webapi/cgiMoin.py,v
retrieving revision 1.11
diff -r1.11 cgiMoin.py
15a16
> from MoinMoin import config
28c29,33
<     return os.environ.get('SCRIPT_NAME', '')
---
>     if config.use_scriptname:
>         scriptname = os.environ.get('SCRIPT_NAME', '')
>     else:
>         scriptname = ''
>     return scriptname

--AdamFeuer and BrianDorsey

BTW, it is much easier, and doesn't change core source, when you add

import os
os.environ['SCRIPT_NAME'] = ''

to moin_config.

MoinCleanUrls (last edited 2008-03-04 08:33:23 by localhost)