MediaWiki/Short URLs

< MediaWiki

Beautifying URLs

 * See also Short URL in the MediaWiki Manual

If your wiki is installed under a "wiki." subdomain

 * See also: Short URL like wiki.example.com/Page_title in the MediaWiki Manual

$wgScriptPath      = ""; $wgScript          = "$wgScriptPath/index.php"; $wgRedirectScript  = "$wgScriptPath/redirect.php"; $wgArticlePath     = "$wgScriptPath/$1";
 * 1) Install MediaWiki in a directory, e.g., ~/wiki.yourdomain.com/
 * 2) Configure your wiki as normal with ugly URLs
 * 3) Modify the following options in LocalSettings.php


 * 1) In the ROOT directory of wiki.yourdomain.com place the following .htaccess file:

RewriteEngine on RewriteBase / RewriteCond %{REQUEST_URI} !^/(skins|stylesheets|images|config)/ RewriteCond %{REQUEST_URI} !^/(redirect|texvc|index).php RewriteRule ^(.*)$ /index.php?title=$1 [L,QSA]


 * 1) NOTE: as of the newer versions of mediawiki, the previous .htaccess file will NOT work. Try this instead:

RewriteEngine on RewriteBase / RewriteCond %{REQUEST_URI} !^/(skins|stylesheets|images|config)/ RewriteCond %{REQUEST_URI} !^/(load|redirect|texvc|index).php RewriteRule ^(.*)$ /index.php?title=$1 [L,QSA]

It seems, that if you're using mediawiki 1.12.0, then the "Special" links will be broken with this approach. One possible solution is to use the patch from this link: http://blog.gugl.org/archives/27

(As of mediawiki 1.19, the Special links do NOT seem to be broken by short URLs.)

If your wiki is installed under a "www." subdomain
See this post in the Dreamhost forums. This method is also described here at Mediawiki.org.

This method will produce URLs (for content pages, not edit pages) that look like www.yourdomain.com/wiki/Content_title

$wgScriptPath = "/w"; $wgArticlePath = "/wiki/$1";
 * 1) Install MediaWiki in www.yourdomain.com/w and not in www.yourdomain.com or www.yourdomain.com/wiki using the Dreamhost control panel
 * 2) Configure your wiki as normal with ugly URLs
 * 3) Modify the following options in LocalSettings.php
 * 1) In the ROOT directory of www.yourdomain.com place the following .htaccess file:

RewriteEngine on RewriteRule ^wiki/?(.*)$ /w/index.php?title=$1 [L,QSA]
 * 1) uncomment this rule if you want Apache to redirect from www.mysite.com/ to www.mysite.com/wiki/Main_Page
 * 2) RewriteRule ^$ /wiki/Main_Page [R]
 * 1) do the rewrite

If your wiki is installed in a /wiki/ directory
$wgScriptPath = "/wiki"; $wgArticlePath = "$wgScriptPath/$1"; RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^wiki/?(.*)$ /wiki/index.php?title=$1 [L,QSA]
 * 1) Install MediaWiki in www.yourdomain.com/wiki using the Dreamhost control panel
 * 2) Configure your wiki as normal with ugly URLs
 * 3) Modify the following options in LocalSettings.php
 * 1) In the ROOT directory of www.yourdomain.com place the following .htaccess file:

Ampersand problems
Using rewrite rules will cause pages with ampersands and possibly question marks in the title to break.

See http://bugzilla.wikimedia.org/show_bug.cgi?id=7424 and http://mail.wikipedia.org/pipermail/mediawiki-l/2005-June/005814.html for further information. This should be updated when somebody figures out if the alias works correctly.