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
Parameters
$egSpecial404RedirectExistingRoots
Quarterly downloads 7 (Ranked 163rd)
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

  • Download and place the file(s) in a directory called Special404 in your extensions/ folder.
  • 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.
  • Yes Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

To users running MediaWiki 1.30 or earlier:

The instructions above describe the new way of installing this extension using wfLoadExtension(). If you need to install this extension on these earlier versions (MediaWiki 1.30 and earlier), instead of wfLoadExtension( 'Special404' );, you need to use:

require_once "$IP/extensions/Special404/Special404.php";

Web server configuration

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

Apache

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

IIS

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

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.

This article is issued from Mediawiki. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.