Manual:Short URL/wiki/Page title -- no root access
From MediaWiki.org
Contents |
These instructions assume you're using Apache and do not have root access. Please read the Recommended guide if you do have root access. You can rewrite URLs, so the server will load "/w/index.php?title=article" for "/wiki/article". The two paths for files and pages (in this example, /w and /wiki), must be different from each other!
[edit] Setup steps
- Choose a virtual directory in which you want your articles to appear. This guide will assume that you choose /wiki/ (as Wikipedia does), articles will then be accessed like http://www.example.com/wiki/Article_title. Do not create this virtual directory and it should not exist in the web root folder! This guide assumes that you have installed MediaWiki in /w/ folder relative to your web root as Wikipedia does, and not in /wiki/ folder.
Note: In case you earlier chose /wiki/ for installing MediaWiki unknowingly, then rename the folder name to new name (here /w/) and replace /wiki/ with new path (here /w/) wherever you see it (one typically only need to change LocalSettings.php file).
Note: The install path must not be same as virtual directory and must not be the web root directory itself, the first point is important, do not try to ignore it to get prettier URLs, or else this method will not work.
- Add or edit the following setting in LocalSettings.php. This will cause the HTML generated by MediaWiki to refer to "/wiki/Articlename" instead of the default:
$wgScriptPath = "/w"; # Path to the actual files (right part of first rewrite rule). Should already be there $wgArticlePath = "/wiki/$1"; # Virtual path (left part of first rewrite rule). MUST be DIFFERENT from the path above! $wgUsePathInfo = true;
- Create or edit .htaccess in your web root directory (typically, public_html) adding:
Alias /wiki /home/johndoe/public_html/w/index.php
OR
RewriteEngine On RewriteRule ^wiki/(.*)$ /w/index.php?title=$1 [PT,L,QSA] RewriteRule ^wiki/*$ /w/index.php [L,QSA] RewriteRule ^/*$ /w/index.php [L,QSA]
RewriteRule defines the rewrite; in the example above, /wiki/Page will cause /w/index.php?title=Page to be loaded instead.
Note: If your /w directory is a symbolic link ("symlink") to some other location, you must allow Apache to follow symlinks using the following code in the .htaccess file:
Options +FollowSymLinks
Note: If you do not want http://example.com/ to redirect you to your wiki because you have other things running too, remove the last RewriteRule.
Note: If your host uses something other than .php to identify php files you will need to adjust the rules accordingly.
Note: If your .htaccess seems to have no effect whatsoever, contact your system administrator to fix this problem. The problem could be that .htaccess has been disabled, the Rewrite module has been disabled or isn't installed, or that the Alias module has been disabled or isn't installed.
Note: If you want to have some backward comatibility with old syntax (for example, when you decide to use new URL syntax after some time, when there are some links on pages on your wiki over the internet), you can add a simple redirect before other rules: RewriteRule ^wiki/index.php/(.*)$ /wiki/$1 [R,L]
ORAlternative .htaccess option:
If you are trying to make the base of the domain the virtual link (example: www.example.com/Main_Page) then the htaccess file is very much different and would look something like below. Place in the base folder (what would normally be a html homepage folder) a .htaccess file the below code and replace the term 'wiki' in the below script with the name of the folder the real files are in.
RewriteEngine On RewriteRule ^([^/]*)$ /wiki/index.php?title=$1 RewriteRule ^/([^/]*)$ /wiki/index.php?title=$1 RewriteRule ^$ /wiki/index.php [L,QSA]
And also in the LocalSettings.php, you need to edit the variable $wgArticlePath (variable shown in step 2) to the below:
$wgArticlePath = "/$1";
OR
If you are on GoDaddy and hosting multiple-sites (like I am with hindupedia.com)
Options -MultiViews RewriteEngine On RewriteBase / RewriteRule ^hindupedia/en/(.*)$ eng/index.php?title=$1 [PT,L,QSA] RewriteRule ^hindupedia/$ eng/index.php?title=$1 [PT,L,QSA]
[edit] More Info
Take a look at the discussion page, as there are some workarounds for errors which could be introduced.

