how to remove index.php from MediaWiki URLs

From Sharkysoft Wiki
Jump to: navigation, search

After completing a normal MediaWiki installation, you may notice that all of the URLs to your wiki's pages have a very non-elegant " index.php " path component. It is considered good form to use URLs that do not betray the technology used in your site's implementation. To give your wiki a truly professional appearance, you need to present human-friendly URLs that non-geeks can understand. This article describes a method for removing " index.php " from (most of) your wiki's URLs.

This article assumes that you have already successfully installed a MediaWiki instance by following the steps outlined in "how to configure multiple MediaWiki instances on a single host."


step 1: Rename your wiki folder.

To achieve short URLs, we'll be taking advantage of URL aliasing. We'll get to that in a moment, but for now, we need to rename the physical folder where your wiki is installed.

cd <your site's document root>
mv wiki wiki-scripts

"w" vs. "wiki-scripts"

The MediaWiki manual recommends renaming your wiki folder to "w". You can certainly do this if you prefer. After all, it is, in fact, the approach used by Wikipedia. At least take the time to think through it carefully. If you decide that "w" is a better name for your wiki scripts folder than "wiki-scripts", by all means, feel free to use "w" instead. Just be sure to appropriate adjust your response to the instructions that follow.

step 2: Update your wiki configuration file.

Since you moved your wiki installation, you'll need to update your wiki configuration file. Open the file in preparation for editing:

cd wiki-scripts
nano LocalSettings.php

Now find the following variables and set them to the values shown. If the variables don't exist, create them:

$wgScriptPath = "/wiki-scripts";
$wgArticlePath = "/wiki/$1";
$wgUsePathInfo = true;
$wgUploadPath = "$wgScriptPath/images";

If you have replaced the default MediaWiki logo that appears in the upper-left corner of your wiki's pages, and the replacement image is in your wiki's installation folder, you may also need to update the logo location as well:

$wgLogo = "$wgScriptPath/logo.png"

step 3: Configure aliasing in Apache.

Finally, in order to make your wiki appear as if it is still installed in the "wiki" folder, we will command Apache to service any request for /wiki as a request for /wiki-scripts/index.php. Begin by opening the virtual host configuration file:

cd /etc/apache2/sites-available
sudo nano (the virtual host file name)

Add the following directive:

Alias /wiki <your site's document root>/wiki-scripts/index.php

Please note a few things about this directive:

  • The first parameter is the URL where you want your visitors to believe the wiki is at.
  • The second parameter is the local file system path to your wiki's main script.
  • Modify either of these parameters as required for your particular installation.

Save the configuration file, close your editor, and restart Apache:

sudo service apache2 restart

step 4: Test your new configuration.

If you've done everything correctly, you should now be able to view all your wiki's pages using a shortened URLs that exclude index.php. But don't take my word for it. Make sure you test your wiki thoroughly.

If you are thorough in your testing, you will discover that the process wasn't perfect. Some URLs, such as those for editing pages or performing other system functions, will continue to present themselves in a less human-friendly format. Fortunately, this is something you can probably live with. In practice, the only URLs that truly need to be human-friendly are those that lead to your site's "entry points." After all, you probably don't expect anyone to ever link to an article's edit page.

If you really care about this, however, you may be able to play around with URL rewriting, an advanced feature of Apache. If you figure out some cool tricks, please share them! Otherwise, quit now and enjoy the fact that most of your wiki's URLs are now human-friendly.

related articles

The inspiration for this article is the "Short URL" manual page from the MediaWiki documentation, at
Personal tools