Own Doings

Guide to setting up mediawiki on Hostgator

Mediawiki Logo

It isn’t all that easy to create a good mediawiki site with URL rewrite (you know… hide the “index.php” part and make it all pretty looking like “YourDomain.ext/wiki/“), So here I put down a step by step method of going through this cumbersome process.

  1. QuickInstall mediawiki in a directory in your public_html folder. Say, in folder “wiki“. (Now, your mediawiki installation is in “YourDomain.ext/wiki/” but yet, when you go to YourDomain.ext, you aren’t redirected to anywhere (like going to en.wikipedia.org redirects you to en.wikipedia.org/wiki/). So now,
  2. Add this to the .htaccess file in public_html to redirect your root folder link to the subfolder in which wiki is installed. (So now, when you enter YourDomain.ext, it takes you to YourDomain.ext/wiki)
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^(www.)?YourDomain.ext$
    RewriteRule ^(/)?$ wiki [L]

    The only change you need to make is to change “YourDomain.ext” to your domain and its extension. This will then redirect everything from the domain to the folder /wiki at that domain. If you want to change that folder just edit the “wiki” part.

  3. Now, I’ll give you a general explanation of how this next step works. Add this to the .htaccess in public_html following what you’ve already entered before.
    RewriteBase /music
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^wiki/(.*)$ ./wiki/index.php?title=$1 [PT,L,QSA]

    RewriteBase‘ defines where the rewrite will start. The example above will match after ‘YourDomain.ext/music‘. If you leave it at just a “/” (i.e. YourDomain.ext/), then rewrite starts after the .ext itself. That’s what you probably want. Remove the “music from the code above.
    RewriteCond‘ makes sure that links to files (like stylesheets or images) are not rewritten, which can break MediaWiki’s formatting in some cases.
    RewriteRule‘ defines the rewrite. In the example above, ‘^wiki/(.*)‘ will invisibly load ‘wiki/index.php?title=$1‘, and the page name (‘$1‘) will replace everything after ‘wiki/‘ .

  4. Add or edit the following setting in LocalSettings.php. This causes the HTML generated by MediaWiki to refer to “/wiki/Articlename” instead of the default.
    $wgScriptPath = "/music/wiki"; #based on requirement, you can keep it as $wgScriptPath = "/wiki";
    $wgArticlePath = "$wgScriptPath/$1";

Conclusion:

So, At the end of working on all of this, summary goes:

Goes into public_html .htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?YourDomain.ext$
RewriteRule ^(/)?$ wiki [L]

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^wiki/(.*)$ ./wiki/index.php?title=$1 [PT,L,QSA]
Goes to localsetting
$wgScriptPath = "/wiki";
$wgArticlePath = "$wgScriptPath/$1";
Disclaimer:

This article is not associated directly with the creators of mediawiki.
Tested on Hostgator servers. Do check out Mediawiki’s manual on Short URLs.

Exit mobile version