Extension:Special404

MediaWiki extensions manual
Special404
Release status: unmaintained
Implementation Special page
Description Provides a simple wiki based 404 special page destination
Author(s) Daniel Friesen (Dantmantalk)
MediaWiki 1.25+
PHP 5.3+
Database changes No
License GNU General Public License 2.0 or later
Download
README
$egSpecial404RedirectExistingRoots
Quarterly downloads 2 (Ranked 138th)
Translate the Special404 extension if it is available at translatewiki.net

The Special404 extension provides a simple wiki based 404 special page destination you can configure for your wiki. The body of the 404 page can also be customized using MediaWiki:Special404-body on your wiki.

Installation

edit
  • Download and move the extracted Special404 folder to your extensions/ directory.
    Developers and code contributors should install the extension from Git instead, using:cd extensions/
    git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/Special404
  • Add the following code at the bottom of your LocalSettings.php file:
    wfLoadExtension( 'Special404' );
    
  • Add some webserver config to redirect 404s to the special page, usually this is in the form of a .htaccess config, more information in the section below or in the extension's README.
  •   Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

Web server configuration

edit

Since this is a 404 handler your webserver will need a little configuration to get it working.

Apache

edit

Using an ErrorDocument doesn't seem to work in apache, whatever the destination you set, Apache seems to direct to something that MediaWiki interprets normally instead of as a request to display the special page, so we use a rewrite rule instead. You can place the following in your .htaccess file to make the extension work. Be sure to tweak the path to index.php to match the proper path to yours. Also make sure that this is the last rewrite rule, you do not want any rewrite rules after this one they will likely be overridden.

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?.*$ /index.php?title=Special:Error404

Keep in mind that it's important that you use /index.php?title=Special:Error404 (with the proper path to index.php of course) and not something like /wiki/Special:Error404 as using the latter causes MediaWiki to treat it normally and direct you to the main page instead of displaying the 404 page.

This rewrite rule is not canonical of cause. For example if you use RewriteBase / rule and your MediaWiki is placed at /w directory (the most usual case) then, the rule will look like this:

RewriteBase /
# ... your other rules ...
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?.*$ w/index.php?title=Special:Error404

Use the following web.config in the directory containing /w (do not put it inside /w), and change wiki.example.com to your domain name.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <outboundRules>
                <preConditions>
                    <preCondition name="ResponseIsHtml1">
                        <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
                    </preCondition>
                </preConditions>
            </outboundRules>
            <rules>
                <rule name="RewriteUserFriendlyURL1" stopProcessing="true">
                    <match url="^wiki/([^/]+/?[^/]*/?[^/]*)/?$" />
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="w/index.php?title={R:1}" logRewrittenUrl="true" />
                </rule>
				<rule name="RootHitRedirect" stopProcessing="true">
					<match url="^$" />
					<action type="Redirect" url="/w/" />
				</rule>
                <rule name="Fix Old Style URLs">
                    <match url=".*" />
                    <conditions>
                        <add input="{HTTP_HOST}" pattern="^wiki.example.com$" />
                        <add input="{PATH_INFO}" pattern="^/wiki/" negate="true" />
                        <add input="{PATH_INFO}" pattern="^/w/" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="\w\index.php?title=Special:Error404" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

The rule in question that makes this extension work for IIS is Fix Old Style URLs. See this page for more details on how these rules were formulated.

Short URLs

edit

If your pages are located at the root directory of your wiki (e.g.: example.com/Page_name), there's no point in installing this extension, because every unknown path of your site will reach MediaWiki, either an existing page, or a non-existing one.

You can edit MediaWiki:noarticletext and MediaWiki:noarticletext-nopermission to customize the text displayed on the non-existing page.