Manual:Short URL/Apache

These instructions help setup Short URLs on 1>Special:MyLanguage/Apache configuration|Apache.

The LiteSpeed webserver is Apache compatible and can be configured in relatively the same way. 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.

''If you have MediaWiki 1.17 or later, you can use this automated wizard rather than following this guide: http://shorturls.redwerks.org/. Please note, however, that it will not work on firewalled or private wikis. In the case of a private wiki, you can still try it out by making your wiki temporarily public by setting   to '' (remember to set it back afterward).

Server config
Should you use the Apache config file or an .htaccess file?
 * If you have access to the global server configuration file (apache2.conf or httpd.conf), you should use that.
 * If you don't have access to that file, you will need to use an  file. There are some limitations to this method, but should be sufficient for most basic short-url configurations.
 * LiteSpeed users should use the  method.

Using the Apache configuration file (apache2.conf or httpd.conf)
The correct configuration file to edit for root configurations may be in one of a number of places. Some places to look:
 * (the mediawiki installation should have set your wiki up here)

Make sure overrides are enabled with by  (it's disabled by default in Ubuntu 12.04 and 12.10).

The Apache config file will likely have a VirtualHost block containing your wiki. If you do have one then that is the location where your rewrite rules will go. RewriteRule config does not inherit so don't put these config options in the global config if you are using a VirtualHost.

After you've setup the config as described below, you'll need to restart Apache. To do that:
 * If you are using Plesk or cPanel it should have a method of restarting the server.
 * Or via command line (using the root user or ):
 * , or
 * (eg on the latest Fedora releases).
 * , or
 * (eg on the latest Fedora releases).

Using an .htaccess file
If you're using a  file you'll need to edit or create the file in either the top directory of your site or the same directory containing your mediawiki installation directory. For example:


 * If your desired url pattern is something like  then create the .htaccess file at
 * If your desired url pattern is something like  then create the .htaccess at

''Note: If you want to use an .htaccess file even when you have access to the main Apache config file, ensure that  is included in an   and that   is enabled in the Apache config. Again, its recommended that you use the Apache config file directly in this case, tho.

''Also 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
First, ensure that the  module is enabled in the Apache config. Also ensure that url rewriting is turned on with:

The two main Apache directives you'll need for this are RewriteCond and RewriteRule. These can be used like this:

In the following patterns:
 * will refer to the directory your mediawiki installation is in, and
 * will refer to the url part you want to use to replace /index.php

Directives for basic short URLs:

Rule for redirecting your root to the main page:

Conditions for selecting a particular host:

Be sure never to include a query part like, because it would cause MediaWiki's built in  handling to be overridden, creating bugs on your wiki.

Sometimes, the above patterns doesn't work (when?). If you're using an Apache config file, the following might work instead:

The end result should look something like this:

or, if you used the way with the "Alias" statement:

The  in the config ensures that Apache has the correct non-ambiguous path. However it does not work on some badly configured free hosts. If you have 404 or 403 issues with your RewriteRules, remove the " " parts and try again.

If your SCRIPT_PATH leads to some other physical location (known as "symlink" in Unix, "shortcut" on Windows, "alias" in Mac OS X), you may need to allow Apache to follow those. You can do so by adding this line above the :

If the path to your script directory is aliased by the webserver via an Alias directive, as it is in Debian among others, the RewriteRule will work as long as you add the PT flag (ie: change  to  )  to Pass Through the request to the next handler - mod_alias, which will correctly redirect the request, as per Stack Overflow

Notes for RewriteRules in .htaccess files
When  is used in an   file, rules are relative to the directory the .htaccess file is in. For .htaccess files, Patterns should never start with a forward slash,, because the URI sub-string will never begin with a.

LocalSettings.php
Make the following change 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: