Manual:Short URL/Apache

These instructions help setup Short URLs on Apache. For information on what Short URLs are or to get instructions on configuration for other servers see Manual:Short URL. If you don't know what webserver you're using since you're using some sort of web hosting service, it's very likely that your host is using Apache.

Plan
Before starting, you need to decide on the name of your virtual "short url" path.

Here we will assume the following:
 * The mediawiki directory is located at:
 * The desired short url format is:

These following instructions have been included in an automated wizard:
 * http://shorturls.redwerks.org/.

If you just want your wiki configured quickly and your wiki is publicly available (it does not work for private and firewalled wikis) then you may want to try that tool first.

Other wise, following along:

Virtual alias (.htaccess)
If you have root access to configure your webserver, follow the Virtual alias (root access) guide instead. .htaccess files are less efficient and don't give you as much control when it comes to fancy setups with multiple domains but they are powerful enough to set up most short url configurations.

First we need to find where we need to edit (or create) the .htaccess file. Find the path that contains both your script path and your article path. Usually this means the top directory of your site, but lets look at a few examples:

Note that if you want to make a redirect from the main domain to your wiki's Main Page (e.g. http://example.org/ &rarr; http://example.org/wiki/Main_Page ). Then you always have to set up the .htaccess file in the top level, even if the other directories are nested deeper.

Setting up the rewrite rules
The first rule you'll need inside of your .htaccess is one to enable the rewrite engine:

Now we need a rule to make your article path a virtual path pointing to index.php. Be sure to replace  and   with the paths you choose in the beginning (if different).

Optionally, include a rule to redirect in-between paths as well to simplify navigation when people visit urls without a page title specified, such as:

The end result should look something like this:

Virtual alias (root access)
The recommended way to setup short URLs in Apache is by editing the config files. This requires that you have access to the server configuration. If you are on a shared host, you most likely don't. If you don't have root you should skip to the .htaccess setup above.

Finding the config file
The correct config file to edit may be in one of a number of places.

Most linux distributions setup Apache with set of  folders setup. The correct config file to edit is the one in  where the configuration for your wiki has been setup. If you haven't set one up and are using the default  for your wiki setup then you can edit.

If your distribution does not have those directories, then you should edit the Apache configuration file directly. This file should be at. Note that it used to be named, if you have a   and no   then   is the one you want to edit.

If your Apache config isn't in any of these spots you should consult the documentation for whatever system you used to install Apache, and find the location of the Apache configuration file.

Editing the config file
Find the directory in which your wiki was installed. When configuring the "Alias" line need absolute paths to your files. So you'll want to know what path on the filesystem your /index.php is located at. This is the same folder you put LocalSettings.php inside of. This should be somewhere in the DocumentRoot for your wiki. If you haven't done any customizations the default DocumentRoot on some linux distributions is /var/www. This can all be a little confusing, because on some systems if you install using the package manager (e.g., Debian; However using package managers to install MediaWiki is strongly recommended against), the path to your wiki may actually be a symbolic link (e.g., to /usr/share/mediawiki/).

The Apache config you need to add consists of a single line. An example is:


 * This is the virtual short url path (without any trailing slash).
 * should be the absolute path on the filesystem to MediaWiki's index.php. This will likely be something like your DocumentRoot and  combined together.

After you've setup the config inside Apache you're going to need to restart Apache to make it apply the new config.
 * If you are using Plesk or cPanel it should have a method of restarting the server.
 * From the command line the command is usually something like,  , or  . These commands need to be run as root, usually by prefixing them with.

LocalSettings.php
We need to make the following configurations in LocalSettings.php:

If you get an "Internal error" page saying "Redirect loop detected!" after you finish configuration you may be using something other than mod_php. If so you need to explicitly turn on short urls using the following line in your LocalSettings.php: