[wp-hackers] ErrorDocument rewrite rule

Daniel Westermann-Clark daniel at acceleration.net
Mon Sep 19 02:21:48 GMT 2005


On 2005-09-18 23:56:06 +0200, Marcus wrote:
> I just had to move a page below another page, which changed the
> permalink, and realized there is no ErrorDocument handling in the
> .htaccess.

WordPress handles 404 responses internally, assuming your theme has a
404.php file.

> I added it manually to classes.php but would it not make sense to
> add it in some way by default?

Other ErrorDocument directives could probably be added by a plugin
that hooks into the mod_rewrite_rules filter, so you wouldn't need to
edit core files.  I've attached an example.

-- 
Daniel Westermann-Clark
-------------- next part --------------
<?php
/*
Plugin Name: Error Documents
Version: 0.9
Description: Add <code>ErrorDocument</code> directives to your <code>.htaccess</code> file.
Author: Daniel Westermann-Clark
Author URI: http://dev.webadmin.ufl.edu/~dwc/
*/

$ERROR_DOCUMENTS = array(
	'500' => '/500.html',
);

add_filter('mod_rewrite_rules', 'error_documents_mod_rewrite_rules');

function error_documents_mod_rewrite_rules($rules) {
	global $ERROR_DOCUMENTS;

	foreach ($ERROR_DOCUMENTS as $code => $file) {
		$rules .= "\nErrorDocument $code $file";
	}

	return $rules;
}
?>


More information about the wp-hackers mailing list