Manual:Short URL/Page title -- Solution for mediawiki-1.12
From MediaWiki.org
This method is currently in use on several mediawiki-1.10 and a mediawiki-1.11 with the the 1.12-version of WebRequest.php, where Bug 11428 is no longer an issue. This method does not work for 1.11.x, not even with setting $wgUsePathInfo to false, I'm not entirely sure of the reason for this.
The method relies on rewrite-rules.
[edit] apache configuration
The only thing your apache needs is mod_rewrite. Other than that, the solution is actually rather simple:
RewriteCond %{REQUEST_URI} !^/(index.php|skins|images|icons|opensearch_desc.php|api.php|~.*) RewriteRule ^/(.*)$ /var/www/your-mediawiki/index.php/$1 [L] # you can skip this if your DirectoryRoot already points to /var/www/your-mediawiki. RewriteRule ^/?(.*)$ /var/www/your-mediawiki/$1 [L]
Explanation: The RewriteCond in line 1 excludes everything that needs to be accessible directly, i.e. the skins/ or images/ directory. The RewriteRule in line 2 is only used if the user requested something that is part of the dynamic content. Everything else is treated by the RewriteRule in line 4 and is only necessary if your DocumentRoot is something different from where your mediawiki is: static files that need to be accessible directly are rewritten without index.php.
This method is very flexible:
- If you need more files/directories accessible directly (i.e. a FavIcon), simply add it to the regular expression of the RewriteCond, which could then look like this:
-
RewriteCond %{REQUEST_URI} !^/(index.php|skins|images|icons|opensearch_desc.php|api.php|favicon.ico|~.*)
- If your wiki is in a sub-directory (i.e. domain.tld/something/Main_Page instead of just domain.tld/Main_Page) you simple have to replace the slash in every line with the appropriate path:
RewriteCond %{REQUEST_URI} !^/something/(index.php|skins|images|icons|opensearch_desc.php|api.php|~.*) RewriteRule ^/something/(.*)$ /var/www/your-mediawiki/index.php/$1 [L] RewriteRule ^/something/?(.*)$ /var/www/your-mediawiki/$1 [L]
[edit] Caveats
- Always consider that order of RewriteRules is important and seemingly unrelated RewriteRules might interfere, if they are too general.
- Giving the absolute path as the destination of the rewrites essentially causes the DocumentRoot-directive to be irrelevant in those cases.
The above two facts are relevant in the following scenario:
- If you use the optional RewriteRule in line 4 you may encounter problems with other sub-directories that are located outside of the mediawiki directory-structure, since it is something of a catch-all phrase. An example-scenario is where your wiki is at domain.tld/ and you want to have statistics at domain.tld/awstats. In this case, you have to make sure, that processing of the /awstats directory stops before the processing for the mediawiki-rules starts. You can do this with a rule that looks something like this:
# all the awstats configuration here #... RewriteRule ^/awstats - [L] # relevant mediawiki config of top-dir goes here.
[edit] mediawiki configuration
Just the good old thing:
$wgScriptPath = ""; # set this to "/something" if your wiki is in a sub-directory. $wgScript = "$wgScriptPath/index.php"; $wgRedirectScript = "$wgScriptPath/redirect.php"; $wgArticlePath = "$wgScriptPath/$1";

