Index: includes/bootstrap.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/bootstrap.inc,v
retrieving revision 1.370
diff -u -F '^f' -r1.370 bootstrap.inc
--- includes/bootstrap.inc	7 Apr 2010 05:15:50 -0000	1.370
+++ includes/bootstrap.inc	9 Apr 2010 13:38:21 -0000
@@ -2045,6 +2045,24 @@ function drupal_maintenance_theme() {
 }
 
 /**
+ * If fast 404 pages have been configured, and this is a matching page
+ * then return a simple 404 page.
+ *
+ * This function is called from drupal_deliver_html_page() at the time when a
+ * a normal 404 page is generated, but it can also optionally be called directly
+ * from settings.php to prevent a Drupal bootstrap on these pages. See
+ * documentation in settings.php for the benefits and drawbacks of using this.
+ */
+function drupal_fast_404() {
+  $fast_paths = variable_get('404_fast_paths', FALSE);
+  if ($fast_paths && preg_match($fast_paths, $_GET['q'])) {
+    header('HTTP/1.0 404 Not Found');
+    print variable_get('404_fast_html', '<html xmlns="http://www.w3.org/1999/xhtml"><head><title>404 Not Found</title></head><body><h1>Not Found</h1><p>The requested URL /' . $_GET['q'] . ' was not found on this server.</p></body></html>');
+    exit;
+  }
+}
+
+/**
  * Return TRUE if a Drupal installation is currently being attempted.
  */
 function drupal_installation_attempted() {
Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.1145
diff -u -F '^f' -r1.1145 common.inc
--- includes/common.inc	7 Apr 2010 17:30:43 -0000	1.1145
+++ includes/common.inc	9 Apr 2010 13:38:25 -0000
@@ -2339,6 +2339,9 @@ function drupal_deliver_html_page($page_
           $_GET['destination'] = $_GET['q'];
         }
 
+        // Check for and return a fast 404 page if configured.
+        drupal_fast_404();
+
         $path = drupal_get_normal_path(variable_get('site_404', ''));
         if ($path && $path != $_GET['q']) {
           // Custom 404 handler. Set the active item in case there are tabs to
Index: sites/default/default.settings.php
===================================================================
RCS file: /cvs/drupal/drupal/sites/default/default.settings.php,v
retrieving revision 1.44
diff -u -F '^f' -r1.44 default.settings.php
--- sites/default/default.settings.php	7 Apr 2010 15:07:59 -0000	1.44
+++ sites/default/default.settings.php	9 Apr 2010 13:38:25 -0000
@@ -393,6 +393,35 @@
 # );
 
 /**
+ * Fast 404 pages.
+ *
+ * Drupal can generate fully themed 404 pages. However, some of the time these
+ * responses are for image or other resource files that are never displayed
+ * to the end user, or from bots that will do nothing with the resulting page.
+ * This can waste bandwidth, and also generate server load.
+ * The options below return a simple, fast 404 page for URLs matching a
+ * specific pattern.
+ *
+ * - 404_fast_paths is a regular expression matching paths to return the
+ *   fast 404 on. If you don't have any aliases ending in htm or html you
+ *   can add '|s?html?' to the expression.
+ * - 404_fast_html is the html to return.
+ * 
+ * Add leading hash signs if you would like to disable this functionality.
+ */
+$conf['404_fast_paths'] = '/.(txt|png|gif|jpe?g|css|css?.|js|js?.|ico|swf|flv|cgi|bat|pl|dll|exe|asp)$/i';
+$conf['404_fast_html'] = '<html xmlns="http://www.w3.org/1999/xhtml"><head><title>404 Not Found</title></head><body><h1>Not Found</h1><p>The requested URL /' . $_GET['q'] . ' was not found on this server.</p></body></html>';
+/*
+ * By default, fast 404s is returned as part of the normal page request
+ * process, will serve valid pages that happen to match, and will also log any
+ * 404s in the Drupal log. Alternatively you can choose to return a 404 now by
+ * uncommenting the following line. This will reduce server load, but will cause
+ * even valid pages that happen to match the pattern to return 404s, rather than
+ * the actual page. It will also prevent the Drupal system log entry.
+ */
+# drupal_fast_404();
+
+/**
  * Authorized file system operations:
  *
  * The Update manager module included with Drupal provides a mechanism for
