Beautifying Mediawiki URLs

From Charlie.Huggardlee.Net

Jump to: navigation, search

As each of my administered wikis is be hosted from a location used primarily to host the wiki, I decided that I wanted to have URLs that were of the form http://subdomain.domain.tld/Article_Name and used mod_rewrite to accomplish this.

In your LocalSettings.php file you need to have Mediawiki generate pretty urls for links like so:

##Set the wiki for pretty urls
$wgScriptPath       = "/w";
$wgArticlePath      = "{$wgScript}/$1";
$wgScriptExtension  = ".php";

And use a .htaccess file like this:

RewriteEngine On
RewriteRule  ^$ w/index.php [L]
 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ w/index.php?title=$1 [L,QSA]

In this manner, your typical web user or spider is able to access files from the directory (such as robots.txt), but any other request would be returned as an attempt at a Mediawiki article. As this causes a HTTP status of 200 OK for any request, this could be bad as web crawlers may start attempting to index non-existent articles! The Missing404 extension should fix that particular issue, by causing the returned HTTP status of a requested non-existent article to instead be 404 Not Found (but human users should notice no interface difference).


Name (required):

Website:

Comment:

To submit your comments, please solve the captcha.

or read what others have said

Web Search
Google
Personal tools