Manual:Short URL/Page title -- Working method with mediawiki-1.11

From MediaWiki.org

Jump to: navigation, search

I spent hours getting this to work with Mediawiki 1.11. This is what ended up working for me after much trial and error.

Here's my working rewrite rules from /.htaccess file:

 RewriteEngine On
 
 # Don't rewrite requests for files in MediaWiki subdirectories,
 # MediaWiki PHP files, HTTP error documents, favicon.ico, or robots.txt
 RewriteCond %{REQUEST_URI} !^/(stylesheets|images|skins)/
 RewriteCond %{REQUEST_URI} !^/(redirect|texvc|index).php
 RewriteCond %{REQUEST_URI} !^/error/(40(1|3|4)|500).html
 RewriteCond %{REQUEST_URI} !^/favicon.ico
 RewriteCond %{REQUEST_URI} !^/robots.txt
 
 # Rewrite http://wiki.example.com/article properly, this is the main rule
 RewriteRule ^/(.*)$ /index.php/?title=$1 [L,QSA]

And here's the required LocalSettings.php settings:

 # short urls
 $wgArticlePath      = "/$1";
 $wgUsePathInfo = false;

[edit] LocalSettings.php wgUsePathInfo = false

This is from an earlier user.

Re: $wgUsePathInfo = false;

Note that setting this global to false means that the semi-friendly solutions for handling ampersands etc will no longer work.

To temporarily fix this 1.11 bug before the developers have released a fixed version, see OrganicDesign:MediaWiki 1.11 title extraction bug for details about how to revert 1.11's title handling code to the 1.10 version.

Note: this method seems to be made for httpd.conf, for .htaccess, remove the first / from the rewrite regex:

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

Note: Please don't do this for Apache/mod_rewrite under Windows: colon causes an HTTP 403 error (the NTFS alternate data streams syntax is something like this: "filename.ext:streamname" -- possibly this occurs only with NTFS; another supposition is the usage of colon for windows drive mapping). Using "^/(.*)$" regex sometimes solves the problem.

[edit] add $wgUsePathInfo = false;

1.11 obviously has a bug, and you need to add this
$wgUsePathInfo = false;
to your config, otherwise you will end up in a situation where you always edit your Index.php instead of the actual page. This information should really be in bold somewhere...

  • The issue seems to be in WebRequest.php::interpolateTitle() where the value of $_GET['title'] is overridden by path info values if $wgUsePathInfo is set. I eventually hacked the code to force it to still use $_GET['title'] if it is not null other wise to go ahead and use title found from the path info. Maybe there should be an override variable that controls which "title" takes precedence. Thus, with this hack I use the following rewrite rules:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond /var/www/path-to/htdocs/$1 !-f
RewriteCond /var/www/path-to/htdocs/$1 !-d
RewriteRule ^/(.*) /index.php/$1 [PT,L,QSA]

and the following local settings:

$wgUsePathInfo      = true;
$wgScriptPath       = "http://www.example.org";
$wgArticlePath      = "/$1";

[edit] Problems related to the the above configuration

  • If you have a page named Programming C++ it will not work because of the plus sign. Take a try, at least in MW 1.12a it doesn't work.(MW1.15rc1 seems have the problem fixed)
  • If you have an extension that includes a .js file to be included by reference in your pages, you need to add extensions/ to the list of directories to be blocked from the httpd rewrite rules (in the same manner as skins/ is).