Manual:Very short URL

Note: This page is a disorganized collection describing various methods and hacks to make MediaWiki use very short URLs, that worked for some users. It is highly encouraged that you use the recommended guide located at Manual:Short URL.

Basics
Please see the article Cool URIs don't change and take a few minutes to devise a stable URL structure for your web site before hopping willy-nilly into rewrites for the URL root. As long as you are rewriting URLs to another location in the same directory, there will always be holes in the redirection; article names that can't redirect, because they have to refer to local files. For example, if /index.php were to redirect, you would get a redirect loop; by preventing that, then an article called index.php wouldn't use the same URL.

Taking note of your DocumentRoot. Which is /home/wiki in this example. Add to /home/wiki/.htaccess or to httpd.conf:

As you can see, the contents of the Directory block are identical to .htaccess.

Adding Exceptions
Some exceptions are needed to prevent looping and to make things work as they should:

For example: RewriteEngine On RewriteRule ^(images/skins)/ - [L] # so skins and images work RewriteRule ^/*$ /index.php?title=Main_Page [L,QSA] RewriteRule ^(.+)$ /index.php?title=$1 [PT,L,QSA]

Remember after you edit httpd.conf to restart Apache.

Edit LocalSettings.php
Edit your LocalSettings.php as follows:

$wgScriptPath      = ""; $wgScript          = "$wgScriptPath/index.php"; $wgRedirectScript  = "$wgScriptPath/redirect.php";  # # Theoretically the only line you should have to edit $wgArticlePath     = "/$1";

Alternatively with Apache 2.2 edit LocalSettings.php as follows:

$wgScriptPath      = ""; $wgScript          = "/index.php"; $wgRedirectScript  = "/redirect.php"; # Theoretically the only line you should have to edit $wgArticlePath     = "/$1";

Or:

$wgArticlePath     = "$wgScript/$1"; (In 1.6.8 MediaWiki version)

Lighttpd
url.rewrite-once = (  "(^/(skins|images|css\?).*$)" => "$1",   "^/([^?]*)(?:\?(.*))?" => "/index.php?title=$1&$2", )

Aliasing method
Please see the article Cool URIs don't change and take a few minutes to devise a stable URL structure for your web site before hopping willy-nilly into rewrites into the URL root.

This modification will make very short url, but return Log in not correctly redirected back and Log out not working (unless you repair the URL by hand) due to improper script handling, as well as wrong handling of page that wasn't edited before.

If you find a solution please add it in here.

Edit LocalSettings.php variables:

$wgScriptPath      = "/mediawiki1.8"; $wgScript          = "/index.php"; $wgArticlePath     = "/$1";

Edit Apache2 configuration file (require mod_alias enabled):

 Alias /mediawiki1.8 /var/lib/mediawiki1.8/ Alias /index.php /var/lib/mediawiki1.8/index.php/ Alias / /var/lib/mediawiki1.8/index.php/

 Options -Indexes  

Warnings and disclaimer
'''This configuration is totally unsupported by the Mediawiki development team. Therefore, future versions may have modifications that break this setup. Indeed, Mediawiki's current code must be modified in two places before it can work.'''

'''Also, it displaces the location for wiki pages. Allowing users to load non-wiki pages in the same webpage will be difficult to set up.'''

What configuration??? The above or below! Fix this header please.

Patching Apache
A few Apache 2 packages are built with this patch already applied (e.g., Gentoo's). Otherwise:

Get the Apache 2 source. Download the patch. Apply, compile, install.

httpd.conf
In httpd.conf or your vhost-config, you'll need to enable some RewriteRules for the wiki's website. Add the following in the appropriate place (e.g., in a VirtualHost):

RewriteEngine On RewriteCond %{REQUEST_URI} !^/(stylesheets|skins|images|config)/ RewriteCond %{REQUEST_URI} !^/(index|redirect|texvc)\.php$ RewriteCond %{REQUEST_URI} !^/error/(40(1|3|4)|500)\.html$ RewriteCond %{REQUEST_URI} !^/(favicon\.ico|robots\.txt)$ RewriteMap ampescape int:ampescape RewriteRule ^/(.*)$ /index.php?title=${ampescape:$1} [L,QSA]
 * 1) Don't rewrite requests for files in MediaWiki subdirectories,
 * 2) MediaWiki PHP files, HTTP error documents, favicon.ico, or robots.txt

Note that the line that prevents rewriting requests for error documents may vary from site to site. Note that you can't use that in .htaccess - RewriteMap isn't valid in htaccess-Context!

Making it work with robots.txt
It is also possible to make regular pages appear shortened like this but other pages will appear in full. This could be done a number of ways, but the most common are to make edit links like http://wiki.site.tld/edit.php?title=Article_Name or http://wiki.site.tld/edit/Article_Name. The first one should be obvious how to implement and the second is just as easy as using a single rewrite rule. This would also have to be done for any other features which you wish to hide from robots, for instance history.

Method for Debian
DON'T install the mediawiki package. It installs to /var/lib/mediawiki1.7 (On stable at least), and makes an alias. This interferes with all the redirects. instead, install from source to /var/www/mediawiki. Then run chmod a+wx /var/www/mediawiki/config then install as you would the package ( http://localhost/mediawiki/config, follow instructions.)

Then run a2enmod rewrite. Edit your virtualhosts file and add the folowing:

RewriteEngine on RewriteCond %{REQUEST_URI} !^/favicon.ico RewriteCond %{REQUEST_URI} !^/robots.txt RewriteCond %{REQUEST_URI} !^/mediawiki/ RewriteRule ^/(.*)$ /mediawiki/index.php/$1 [L,QSA]
 * 1) Don't rewrite requests for files that really exist or should return 404.
 * 1) Rewrite http://wiki/article -- this is the main rule

Then add this to /var/www/mediawiki/LocalSettings.php

$wgArticlePath = "/$1";

Run apache2ctl graceful one more time, and you should be done.