MediaWiki Short URL Solution for Subdomains
April 8th, 2009 at 4:20 pm (Stubble)
The subdomain is particularly challenging for those who don’t want to be mucking about with httpd.conf files or otherwise cannot. That’s not to say it is less onerous to achieve the same result within the confines of a domain.
Most often, a subdomain, e.g., wiki.blancmange.net, is nothing more than a virtual domain that points to some subdirectory in the htdoc/public_html root of the parent domain, i.e., blancmange.net (www.* is, as a rule, an alias of the parent domain, rather than a subdomain). In these cases, happily, the attainment of short urls involves only two simple steps (distilled from many hopeful but ultimately unworkable solutions):
- Edit the LocalSettings.php file in the MediaWiki root directory.
- Edit an .htaccess file that will reside in the same directory
In the LocalSettings.php file you will add or change the following to what was automagically generated during the setup of your MediaWiki install:
- $wgScriptPath = “”;
- $wgArticlePath = “$wgScriptPath/$1″;
Just to be clear, the value assigned to the first variable is a pair of quotes (avoid using the smart quotes in this post). The one assigned to the second variable is derivative of the first. The effect is that the url for the main page will look like this:
wiki.blancmange.net/Main_Page
The next step is to add Apache mod_rewrite statements to the .htaccess file. Here are the statements that seem to make it all happen:
RewriteEngine On
RewriteCond %{HTTP_HOST} wiki.blancmange.net
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?title=$1 [L,QSA]
The really key bit here is the second statement. With it present where it is, the 404 errors you’ve been confounded by are finally brought to an end.
It should be noted that this was achieved on version 1.14.0.

