Extension:Special404

From MediaWiki.org
Jump to navigation Jump to search
MediaWiki extensions manualManual:Extensions
Crystal Clear action run.svg
Special404

Release status:Extension status stable

ImplementationTemplate:Extension#type Special page
DescriptionTemplate:Extension#description Provides a simple wiki based 404 special page destination
Author(s)Template:Extension#username Daniel Friesen (Dantmantalk)
MediaWikiTemplate:Extension#mediawiki 1.23+
PHPTemplate:Extension#php 5.3+
Database changesTemplate:Extension#needs-updatephp No
LicenseTemplate:Extension#license GNU General Public License 2.0 or later
Download
README
ParametersTemplate:Extension#parameters

$egSpecial404RedirectExistingRoots

Translate the Special404 extension if it is available at translatewiki.net

Check usage and version matrix.

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 place the file(s) in a directory called Special404 in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php:
    require_once "$IP/extensions/Special404/Special404.php";
    
  • 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.
  • YesY 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) than 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