User:Barrylb/Fix for ampersand in titles

MediaWiki extensions manual
Fix for ampersand in titles
Release status: unknown
Implementation Interface
Description Ampersands or & appear in the wiki page title as &.
Author(s) Barrylb
MediaWiki 1.6.7
License No license specified
Download No link
Translate the Barrylb/Fix for ampersand in titles extension if it is available at

Because of URL Rewrites, ampersands (&) appear in the wiki page title as &.[1]

Patching Apache[edit]

Below Apache 2.0[edit]

If you're using URL rewriting and want to be able to use the ampersand (&) in page titles, you'll need to patch Apache to properly escape the character when generating the query string. A patch for Apache 1.3.26 is available as maintenance/apache-ampersand.diff in the MediaWiki source. (As of 2005, no patch is yet available for Apache 2.0.x.)

Change your mod_rewrite config like so[2]:

RewriteEngine On
RewriteMap ampescape int:ampescape
RewriteRule ^/wiki/(.*)$ /w/wiki.phtml?title=${ampescape:$1} [L]
RewriteRule ^/wiki$ /w/wiki.phtml

Patching without Apache[edit]

If an editor does not have the ability to patch Apache like Wikipedia's solution, try this solution which modifies the MediaWiki code to extract the title from the $_SERVER variable. [WHERE?]

This is tested and working on 1.6.7.

Modify includes/WebRequest.php - function WebRequest() - put the following after global $wgUsePathInfo;:

  global $wgArticlePath;
  if (strpos($_SERVER['SCRIPT_NAME'], 'index.php') === false) {
    $articlePathPart =  str_replace('$1','',$wgArticlePath);
    $_GET['title'] = $_REQUEST['title'] = str_replace($articlePathPart, '', $_SERVER['SCRIPT_NAME']); 

See also[edit]


  1. This is because of the Apache mod_rewrite which makes friendly URLs in titles.
  2. This way, /wiki/AT&T correctly becomes /w/wiki.phtml?title=AT&T instead of /w/wiki.phtml?title=AT&T, which breaks up into "title=AT" and a useless "T".