[Mediawiki-l] Ampersand strips rest of page title in MW 1.4 installation

Brion Vibber brion at pobox.com
Thu Jun 30 19:23:35 UTC 2005


Tim Pritlove wrote:
> On 29.06.2005, at 19:35, Brion Vibber wrote:
>> Tim Pritlove wrote:
>>> Pages that contain an Ampersand no longer show up. Whenever I  click  on
>>> a link to that page, it strips the page title beginning from the
>>> Ampersand resulting in an unknown page name.
>>
>> Are you using Apache rewrite rules? Are they different? What are they,
>> exactly?
>
> i use rewriting. The rules are:
>
>         <IfModule mod_rewrite.c>
>                 RewriteEngine On
>                 RewriteCond %{REQUEST_METHOD} ^TRACE
>                 RewriteRule .* - [F]
>                 RewriteRule ^/wiki/?(.*)$ /mediawiki/index.php?title= $1
> [L]
>         </IfModule>

Apache's mod_rewrite un-escapes various hex-encoded characters which
have special meaning in URLs, most insidiously the question mark (?) and
ampersand (&).

The result of this is that an incoming URL like:

   /wiki/AT%26T

gets rewritten to:

   /mediawiki/index.php?title=AT&T

whose query string gets parsed into this list:

  title => 'AT'
  T     => ''

There's an easy workaround, and a more complete fix. The easy workaround
is (at least if you're using PHP as an Apache module) to switch to using
the PATH_INFO-style URLs:

   RewriteRule ^/wiki/?(.*)$ /mediawiki/index.php/$1 [QSA,L]

The '&' character has no special meaning in the _path_ part of the URL
so the rewritten form works:

   /mediawiki/index.php/AT&T

However now you'll find that titles with question marks fail similarly,
because the question mark separates the path from the query string:

   /wiki/Got_Milk%3F_(advertising_slogan)
   /mediawiki/index.php/Got_Milk?_(advertising_slogan)


On our own servers we use a patched version of Apache which adds a
rewrite processing function to specifically re-escape the ampersand into
%26. You'll find a patch for Apache 1.3.x in the MediaWiki distribution
as maintenance/apache-ampersand.diff

Use is something like:

     RewriteMap ampescape int:ampescape
     RewriteRule ^/wiki/(.*)$ /w/index.php?title=${ampescape:$1} [QSA,L]


Alternatively, you might try replacing the rewrite rule with an alias to
index.php:

   Alias /wiki /var/www/mediawiki/index.php

or other such tricks to use the built-in PATH_INFO usage.

-- brion vibber (brion @ pobox.com)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 253 bytes
Desc: OpenPGP digital signature
Url : http://lists.wikimedia.org/pipermail/mediawiki-l/attachments/20050630/3b19e74b/attachment.pgp 


More information about the MediaWiki-l mailing list