In the frontier town of Typhoid, Wyoming, whenever the harsh conditions killed off a bunch of citizens the rest would just go dig themselves up a new passel of townsfolk from the nearby people mine.
Daze of Our Lives

MediaWiki Short URL Solution for Subdomains

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 this case, wiki — 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). Assuming you have set up a subdomain called wiki.blancmange.net that points to a subdirectory /wiki, you need to:

  • 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.  It does depend on permission to use .htaccess files.  With it present where it is, the 404 errors you’ve been confounded by are finally brought to an end.

Additional: add the following line to redirect common links to your wiki, just in case people have linked it that way. Assuming the same subdomain above, you would write the following in the .htaccess file, above the other entry:

RedirectMatch /wiki/(.*)$ http://wiki.blancmange.net/$1

This will forestall broken links, at least to some extent.

It should be noted that this has been achieved on versions 1.14.0 – 1.16.4.