Jump to content

User:MathiasErtl/Apache Macro for MediaWiki

From mediawiki.org

If you have more than one MediaWiki and you might want to use the mod_macro Apache-module. With this module, you only have to write the configuration once and it is possible to update the apache-configuration for all wikis at once.

Install mod_macro

[edit]

See mod_macro Documentation.

Write a macro

[edit]

This is of course essentially up to you.

Below is what we use in our WikiFarm. It is a bit more powerful since it does some very nice things:

  • Uses very-short-URLs (you must configure your wiki to use that, too)
  • Redirects index.php/PAGENAME links to /PAGENAME
  • Allows you to specify additional exceptions for the index.php-rewriting

Just save this code to a file:

<Macro mediawiki $path $scriptPath $excludes>
        RewriteEngine On

        RewriteRule ^$scriptPath[iI]ndex.php/(.*) $scriptPath$1 [L,R=301]

        RewriteCond $excludes !=-
        RewriteCond %{REQUEST_URI} !^$scriptPath(index.php|skins|images|icons|opensearch_desc.php|api.php|extensions|$excludes)
          RewriteRule ^$scriptPath(.*)$ $path/index.php/$1 [L]

        RewriteCond $excludes =-
        RewriteCond %{REQUEST_URI} !^$scriptPath(index.php|skins|images|icons|opensearch_desc.php|api.php|extensions)
          RewriteRule ^$scriptPath(.*)$ $path/index.php/$1 [L]

        RewriteRule ^$scriptPath?(.*)$ $path/$1 [L]

        <Directory $path>
                Options -All +FollowSymLinks +MultiViews
                AllowOverride AuthConfig Indexes
                Order allow,deny
                allow from all
        </Directory>
</Macro>

Next, you must include it in httpd.conf. If you plan on having more than one macro, you can use wildcards:

Include /etc/apache2/macros/*

The final step is to actually use the macro where-ever you want a MediaWiki:

Use mediawiki /path/to/a/sub/wiki /sub -
Use mediawiki /path/to/your/wiki / foo|bar|whatever

The first parameter ('/path...') is the path where your wiki is located. The second parameter is the scriptPath to your Wiki. With the third parameter you can optionally specify additional excludes, i.e. if you want to have other projects in a subdirectory. If you don't want any additional excludes, specify a dash ('-'), otherwise, separate each of them with a pipe ('|') - they become part of a regular expression.