SEO friendly URLs in MediaWiki - on Apache using htaccess

In this tutorial we demonstrate how you can make your wiki page URLs SEO friendly on Linux - Apache based hosting using htaccess URL rewriting. SEO friendly URLs which are easy to read and remember for anyone if they want to keep in mind any page of your wiki.

What are SEO friendly URLs?

SEO - Search Engine Optimization is a technique by which we enable anyone to find our web page(or in this case wiki page) reachable via any search engine(e.g. google). each search engine assign a page rank to each page in website, better the page rank, better the chances to get found in search. Thus SEO friendly URLs are form of URLs which are better parsed and presented by search engine while looking for results from your page.

Why do we need SEO friendly URL?

Because they are easy to read, understand, remember and perform better in SEO. and they doesn't involve or let any general visitor know the technical background of your web page(other than HTML). There are no typical URL stuff in an SEO friendly URL which is not required to be there.

How can we make our MediaWiki URLs SEO friendly ?

Hm, now we are coming to the point. Although there is a Manual page dedicated to this in official Mediawiki Docs, but we thought we should do this tutorial anyway. May be we can make it to the point.

Because most of shared hosting and server systems are based on Linux and apache we are going to demonstrate example for linux based apache systems. Before we start a word of caution. While shortning URLs never make it relative to the root '/' or say because Mediawiki have some defined namespaces so it is better to avoid any chance that your page name may clash with it. So we will use 'wiki' as our base for page names in URLs.

This overall process is only two step work, first we write the script to rewrite the url on server level. In the root directory of your mediawiki installation you will find the file called '.htaccess' if not, please create one. and write the following code.

RewriteEngine On
RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/index.php [L]
RewriteRule ^/*$ %{DOCUMENT_ROOT}/index.php [L]

Above code asks apache to turn on its URL rewriting engine and let the rewrite rules work. Second line redirect all the request coming to base file which is index.php to /wiki and at last it make index.php work as root and then system would not require the index.php as part of url.

At last you need to add one more line to your LocalSettings.php file in MediaWiki root, and let Mediawiki know you have change the URL structure.

$wgArticlePath = "/wiki/$1";

This will allow MediaWiki to pass the URL parameters to new path which has 'wiki' as prefix.

Now if you go to your wiki you will find no index.php in URL and base path is now
And that is it. your Wiki is now SEO friendly with its easy to read and understand URls.

URL structure Before:

Mediawiki Url before shortening


URL structure After:

Mediawiki url after making shortening