User:Fo0bar/MediaWiki root articles


One of my pet peeves is seeing wiki URLs such as There are many recipes out there for shortening that to "Wikipedia-style" URLs such as, but I wanted to take it further. I wanted simply to be the home page, and to be a normal article.


  • Set up a normal MediaWiki installation in the directory /w under the document root.
  • Edit /w/LocalSettings.php.
  • Edit the virtual host's .htaccess.

LocalSettings.php configuration[edit]

$wgScriptPath = "/w";
$wgArticlePath = "/$1";

.htaccess configuration[edit]

<IfModule mod_rewrite.c>
# Turn on mod_rewrite
RewriteEngine On

# If you are converting from a static site to a wiki,
# you'll want to make redirections to the new article.
RewriteRule ^old-file.html$ [R=permanent,L]

# This hack lets you essentially gets rid of the redirection
# to "Main Page".  Conversely, if you go to,
# it sends an permanent external redirection to
RewriteRule ^Main_Page$ [R=permanent,L]
RewriteRule ^$ /w/index.php?title=Main_Page&redirect=no [QSA,L]

# Finally, if we've gotten this far, process it as if it's an article,
# UNLESS it's a physical file/directory/symlink.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ /w/index.php?title=$1 [QSA,L]

One step further: action URL rewrites[edit]

The above process makes the article URLs look pretty, but index.php is still referenced in most actions. To solve that, we can use mod_rewrite to map to better URLs, and tell MediaWiki to use them for actions. In this guide, becomes

LocalSettings.php configuration[edit]

foreach($wgActions as $action => $value) {
  if($value === false) { continue; }
  if($action == 'raw') { continue; }
  $wgActionPaths[$action] = "$wgScriptPath/action/$action/$1";
$wgActionPaths['view'] = $wgArticlePath;

.htaccess configuration[edit]

Insert the following above the RewriteConds above:

RewriteRule ^w/action/([a-z]*)/(.*)$ /w/index.php?action=$1&title=$2 [QSA,L]