Provided stuff for

  • CleanUrls - multiple hostnames with different paths pointing to the same wiki
  • PITS 01266 - refcount uses invalid XHTML markup

Well, I'm using the variant .htaccess and pmwiki.php in the Same Directory.
Works fine if you've attached one hostname to one address.

I then needed a solution to access my wiki by




pointing to the same wiki.

Here's the result (for Apache 2.2 and later):

RewriteEngine  On
# No RewriteBase since we Base ourselves

RewriteCond %{HTTP_HOST}   ^subdomain\.example\.com$  [NC]
RewriteRule .? - [E=REWRITEBASE:/]
RewriteCond %{HTTP_HOST}   ^(www\.)?example\.com$     [NC]
RewriteRule .? - [E=REWRITEBASE:/in/this/subdir/]
# more RewriteCond-RewriteRule pairs may follow further hostnames

RewriteRule ^$                      %{ENV:REWRITEBASE}pmwiki.php      [L]
RewriteRule ^index\.php$            %{ENV:REWRITEBASE}pmwiki.php      [L]
RewriteRule ^([A-Z0-9\xa0-\xff].*)$ %{ENV:REWRITEBASE}pmwiki.php?n=$1 [QSA,L]

First of all, RewriteBase cannot be used anymore, because there's no conditional form of it.
Additionally I use a server environment variable to store the path that points to the wiki directory.

So, a RewriteCond matches against a hostname via %{HTTP_HOST} and if the pattern matches, the immediately following RewriteRule is used: match whatever (=.?), keep it unchanged (=-) and set the environment variable REWRITEBASE to the specified path (must precede and follow a /). This combination can be done multiple times for every hostname you use on the same wiki.

Once the environment variable is set, it prepends each pmwiki.php in the following rules.
Unfortunately a default value for REWRITEBASE can't be set before Rewriting by


since the SetVar module is one of the latest being executed within Apache. The SetVarIf module would work indeed, but didn't checked it out further.

RRipley 2011-09-16 10:30pm UTC