Matt's Musings

September 9, 2005

mod_rewrite fun

Filed under: Debian — matt @ 12:52 am NZST

I’m currently in the process of adopting the Debian PHPwiki Package, which involves fixing a whole lot of bugs and upgrading to PHPwiki 1.3.10 (latest stable release).

1.3.10 changed some internal logic relating to URL handling so the old rewriting scheme no longer works. I’m trying to come up with a new all-singing, all-dancing configuration setup that will allow the package to work “out of the box” in the following 4 setups with as little modification to the default configuration files as possible (ie. as little use of sed/awk to insert config values as possible).

  1. mod_rewrite enabled, installed in subdir, eg (http://www.example.org/phpwiki/HomePage)
  2. mod_rewrite disabled, installed in subdir, eg (http://www.example.org/phpwiki/index.php/HomePage
  3. mod_rewrite enabled, installed in root, eg (http://www.example.org/HomePage)
  4. mod_rewrite disabled, installed in root, eg (http://www.example.org/index.php/HomePage

The PHPwiki source code is always installed in /usr/share/phpwiki/. The basic configuration that I’ve come up with is as follows:
apache.conf

<ifmodule mod_rewrite.c>
        RewriteEngine on
        RewriteRule /phpwikidata/(.*)$  /usr/share/phpwiki/$1   [L]
        RewriteRule <url>(.*)       /usr/share/phpwiki/index.php/$1  [L]
</ifmodule>

<ifmodule !mod_rewrite.c>
        Alias  <url>                 /usr/share/phpwiki/
        Alias /phpwikidata/         /usr/share/phpwiki/
</ifmodule>

<directory /usr/share/phpwiki/>
        DirectoryIndex index.php
        Options +FollowSymLinks
        AllowOverride None
        order allow,deny
        allow from all
</Directory>

config.ini

DATA_PATH = /phpwikidata
; Note following two are commented out
;USE_PATH_INFO = false
;VIRTUAL_PATH = /phpwiki

This configuration works perfectly for cases 1 and 2 listed above. It requires the apache config snippet to be generated by the postinst script (<url> is replaced with either ‘/phpwiki/’ or ‘/’), but the actual config.ini file does not need to be processed at all.

However this configuration does not work for cases 3 and 4 as PHPwiki seems to get confused as to where it is installed and starts linking to http://www.example.com//HomePage (double slash) which PHPwiki then interprets as the page ‘/HomePage’ which doesn’t exist. To combat this problem we can modify config.ini to specify the virtual path (or URL) that phpwiki appears at. For example:

config.ini

DATA_PATH = /phpwikidata
USE_PATH_INFO = true
VIRTUAL_PATH = <urlpath>

This configuration now works perfectly for cases 1 and 3 listed above, however it breaks cases 2 and 4. Additionally it requires us to process config.ini to replace the <urlpath> variable. This is bearable however as it is a simple subsitution.

So the summary of the problem is: using my current configuration, the USE_PATH_INFO and VIRTUAL_PATH directives must be present if mod_rewrite is enabled in apache, but must be absent otherwise. This is hard to detect in a postinst script, makes generating the config.ini file much more complex and will no doubt cause havoc with future upgrades.

Does anyone know of a better way that I can make all four scenarios above work with minimal (preferably none) modifications to config.ini?

If not, given that I’d prefer not to put logic into the postinst to detect mod_rewrite state I think I’ll make the package only support installing in a subdirectory and add a notice to the user (README.Debian or similar) telling them how to manually configure it for usage in the webroot. Would this be an acceptable fall back position?

No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

Powered by WordPress