Manual:Short URL

According to World Wide Web inventor Tim Berners-Lee, good webpage addresses should never change. Short webpage addresses which hide complex programming code from the webpage address is good for webpage visitors. Please take a few minutes to devise a stable URL structure for your website before getting started, to reduce problems later. This page has been divided into separate "how to" mini-guides listed below to make things easier.

MediaWiki's default installation path usually look like these examples:
 * (installed as root user)
 * (installed with a shared hosting provider)

MediaWiki's default webpage addresses look like these examples:
 * (MediaWiki version 1.11.0) or

Using the methods below, short webpage addresses can be changed to addresses such as these:

What's wrong with long URLs?
Before starting, we must first ask "what's wrong with long URLs?" Answer: nothing much. Indeed only long URLs work in all hosting environments -- a good thing to know if one day you move your wiki to a hosting environment where you can't use short URLs.

However, we have decided that we are willing to pay the price (trial and error configuration work as detailed below) for the admittedly purely cosmetic surgery to make our URLs look better ("pretty" vs. "ugly"). Hence we commence our journey...

Forcing long URLs
However before we depart, we list the antidote just in case, $wgUsePathInfo=false; $wgScriptPath=""; #force long URLs

Shared hosting
Most shared hosting systems do not allow changes to httpd.conf. If you are using a shared host, before trying to solve the problem yourself, first try asking your hosting provider. Your hosting provider may well solve your problem for you. If that doesn't work out, depending on your hosting provider, you may be able to make use of a .htaccess file to achieve your goals.

If you have a choice, you should edit httpd.conf, which requires root access and is the preferred method because your wiki will perform better. You only need to edit either .htaccess or httpd.conf, not both.

Recommended setup (Wikipedia style)
The following setup is used on Wikipedia, and tends to be robust and easy to set up. However, it does require root access, and doesn't rewrite all URLs. This setup is recommended for use by MediaWiki developers and should be used unless you really dislike some aspects of it, or of course you can't use it.

Why to do it

 * This method is reliable and guaranteed to work in all versions of MediaWiki, for the indefinite future. Other schemes are not tested by MediaWiki developers and might break when changes are made to the software.
 * You should not rewrite articles to be in the document root. URLs like   may look prettier to you than , but the former causes a variety of problems, including problems with robots.txt, favicon.ico, and script paths.
 * Not all URLs are rewritten, but this is good. This allows you to easily block search engine spiders from doing anything but viewing articles with a single simple rule.  Likewise, you can easily separate out actual article views from other accesses in log analysis, and so on.  Links to edit pages and so on are slightly less memorable, but this is no big deal: the important thing is the articles.
 * The method uses Alias instead of Rewrite. This is simpler and more reliable (although unfortunately, it requires root access).

Why not to do it

 * You are not using Apache.
 * You do not have root access.

How to do it
First of all, ensure that 1) you are using Apache and 2) you have the right to modify httpd.conf (.htaccess is not enough!). If either of these is wrong, you cannot use this exact method; you need to modify it appropriately, or use some other method.

  Install your wiki to some directory. For the purposes of this guide we will assume you install it in  relative to your web root, as Wikipedia does. If you choose another path, replace  with that path wherever you see it.  Choose a directory that your articles should live in. We will assume that you choose, as Wikipedia does. Then articles will be accessed like. If you choose another path, replace  with that path wherever you see it. '''Do not create this directory. It should not contain any files and should not exist in the filesystem. The path also must not be the root directory, or the same as the virtual directory'''. The last point is important: do not try to ignore it to get prettier URLs, or else this method will not work.  At the bottom of LocalSettings.php, add the line  and.  Edit httpd.conf to contain the rule. Note that the second path is relative to the filesystem root, not the web root! This might be, for instance,, if   is your web root.  Make Apache reread its configuration file (gracefully restart). You might use, for instance,  or a similar command as root, or use features of WebHost Manager or similar software.  In your web root, create a file called robots.txt if one does not already exist. Then add the following to the end of the file: User-agent: * Disallow: /w/ Disallow: /wiki/Special:Search Disallow: /wiki/Special:Random The first "Disallow" rule stops spiders from indexing histories, edit pages, and other worthless things. These will cause duplicate content to be indexed, as well as pages like history and edit pages that are useless to anyone doing a web search. The second and third rules stop spiders from indexing two special pages that might confuse them, and generally be unhelpful. 

You're now done: your wiki should be working perfectly. If not, go to irc://irc.freenode.org/mediawiki and report any problems.

Other techniques: how-to mini-guides
Anyone is welcome to create a "how to" solution page and list them below. Please use a sensible name for the page, one that fits in with the below names. When each unique solution has its own page, readers can skip complexity they do not want. Keep it simple, readable, short, with a separate page per separate solution.

example.com/Page_title
How to create: example.com/Page_title webpage addresses
 * Manual:Short URL/Page title -- PHP as a CGI module, no root access [[Image:Smiley.svg|20px]] x30 [[Image:Face-sad.svg|20px]] x7
 * Manual:Short URL/Page title -- Aliasing method--Root access [[Image:Smiley.svg|20px]]x2 [[Image:Face-sad.svg|20px]] x6
 * Manual:Short URL/Page title -- Working method with mediawiki-1.11 [[Image:Smiley.svg|20px]] x20 [[Image:Face-sad.svg|20px]]x5 used this method[[Image:Face-sad.svg|20px]] x2

example.com/wiki/Page_title
How to create: example.com/wiki/Page_title webpage addresses


 * Manual:Short URL/wiki/Page title -- PHP as a CGI module, no root access [[Image:Smiley.svg|20px]]x8 [[Image:Face-sad.svg|20px]]x4
 * Manual:Short URL/wiki/Page title -- no root access [[Image:Smiley.svg|20px]]x7 [[Image:Face-sad.svg|20px]]x4
 * Manual:Short URL/wiki/Page title -- Both no root and root access [[Image:Smiley.svg|20px]]x2
 * Manual:Short URL/wiki/Page title -- No hidden subdirectory, no root access [[Image:Smiley.svg|20px]]x1

Root access

These methods require that you have access to the server configuration. If you are on a shared host, you most likely don't; see the "no root access" examples instead.


 * Manual:Short URL/wiki/Page title--root access -- EASY [[Image:Smiley.svg|20px]]x12
 * Manual:Short URL/wiki/Page title -- with aliases--root access [[Image:Smiley.svg|20px]]x5 [[Image:Face-sad.svg|20px]]x2
 * Manual:Short URL/wiki/Page title -- Apache rewrite--root access[[Image:Smiley.svg|20px]]x4 If the Alias method is not suitable (for example, you use PHP as a CGI), you can use Apache instead.
 * Manual:Short URL/wiki/Page title -- Lighttpd rewrite--root access

www.example.com/sub_directory/wiki/Page_Title

 * Manual:Short URL/sub_directory/wiki/Page Title -- .htaccess [[Image:Smiley.svg|20px]]x1 [[Image:Face-sad.svg|20px]]x1

wiki.example.com/Page_title
How to create: wiki.example.com/Page_title webpage addresses


 * Manual:Short URL/wiki.example.com/Page_title--difficult [[Image:Face-sad.svg|20px]]
 * Manual:Short URL/wiki.example.com/Page_title--Subdomain with no Subdirectory in Article URL [[Image:Smiley.svg|20px]]x11[[Image:Face-sad.svg|20px]]
 * Manual:Short URL/wiki.example.com/Page_title--Subdomain using mod-rewrite [[Image:Face-sad.svg|20px]]
 * Manual:Short URL/wiki.example.com/Page_title--Subdomain using Lighttpd
 * Manual:Short URL/wiki.example.com/Page_title--Enabling a wiki using Apache Rewrite [[Image:Smiley.svg|20px]]

Ampersand (&) problem
Explanation: This problem shows up when you have page titles with symbols in (such as &, ?, #, + and /) that, despite being correctly encoded in the link are not being passed correctly from mod_rewrite to the script. This manifests in 404 page not found errors, because the title gets cut off at the special character. e.g. Clicking on a link "John & Maria's page" gets a 404, because MediaWiki is looking for a page names "John ".

Solutions:
 * Manual:Short URL/Ampersand solution with root access
 * Manual:Short URL/Ampersand semi-friendly solution with root access

Tricks

 * Manual:Short URL/IIS6 [[Image:Smiley.svg|20px]]
 * Manual:Short URL/Prevent bots from crawling index.php
 * Manual:Short URL/Ignoring the Trailing slash
 * Manual:Short URL/Allowing for escaped characters in URI [[Image:Smiley.svg|20px]]

Troubleshooting

 * I received a looping alias/rewrite errors such as: 'Cannot find page www.example.com/wiki/wiki/wiki/wiki/wiki/ [...] /index.php' Solution: Manual:Short URL/Repeated directory errors
 * Manual:Short URL/Page title -- Working method with mediawiki-1.11