Index: .htaccess =================================================================== RCS file: /cvs/drupal/drupal/.htaccess,v retrieving revision 1.102 diff -u -F^f -r1.102 .htaccess --- .htaccess 9 Jun 2009 05:08:16 -0000 1.102 +++ .htaccess 13 Jun 2009 21:02:47 -0000 @@ -16,11 +16,19 @@ # Make Drupal handle any 404 errors. ErrorDocument 404 /index.php -# Force simple error message for requests for non-existent favicon.ico. - - # There is no end quote below, for compatibility with Apache 1.3. - ErrorDocument 404 "The requested file favicon.ico was not found. - +# The following lines prevents Drupal from handling 404 errors for certain +# types of static files, such as images and CSS. +# +# This can help reduce the server's load because 404s for such files do not +# cause a full Drupal bootstrap. +# + +# If you do not use aliases ending in htm/html replace the above line with the +# commented line below. You need to make similar changes in the Rewrite section +# below, and your settings.php file. +# + ErrorDocument 404 "404 Not Found

Not Found

The requested URL was not found on this server.

+
# Set the default handler. DirectoryIndex index.php index.html index.htm @@ -84,10 +92,24 @@ # uncomment the following line: # RewriteBase / + # The following lines prevents Drupal from handling 404 errors for certain + # types of files, such as images and CSS. + # + # This can help reduce the server's load because 404s for such files do not + # cause a full Drupal bootstrap. + RewriteCond %{REQUEST_FILENAME} !-f + RewriteCond %{REQUEST_URI} !/files/ + RewriteCond %{REQUEST_URI} \.(txt|png|gif|jpe?g|shtml?|css|js|ico|swf|flv|cgi|bat|pl|dll|exe|asp)$ + # If you do not use aliases ending in htm/html replace the above line with the + # line below. You need to make a similar changes in the FilesMatch section above + # and your settings.php file. + # RewriteCond %{REQUEST_URI} \.(txt|png|gif|jpe?g|s?html?|css|js|ico|swf|flv|cgi|bat|pl|dll|exe|asp)$ + RewriteCond %{REQUEST_URI} !^404.%1$ + RewriteRule ^(.*)$ 404.%1 [L] + # Rewrite URLs of the form 'x' to the form 'index.php?q=x'. RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d - RewriteCond %{REQUEST_URI} !=/favicon.ico RewriteRule ^(.*)$ index.php?q=$1 [L,QSA] Index: modules/system/system.admin.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.admin.inc,v retrieving revision 1.156 diff -u -F^f -r1.156 system.admin.inc --- modules/system/system.admin.inc 13 Jun 2009 19:28:57 -0000 1.156 +++ modules/system/system.admin.inc 13 Jun 2009 21:02:48 -0000 @@ -1404,7 +1404,7 @@ function system_file_system_settings() { '#title' => t('File system path'), '#default_value' => file_directory_path(), '#maxlength' => 255, - '#description' => t('A file system path where the files will be stored. This directory must exist and be writable by Drupal. If the download method is set to public, this directory must be relative to the Drupal installation directory and be accessible over the web. If the download method is set to private, this directory should not be accessible over the web. Changing this location will modify all download paths and may cause unexpected problems on an existing site.'), + '#description' => t('A file system path where the files will be stored. This directory must exist, be writable by Drupal and contain the word \'files\' somewhere on the path. If the download method is set to public, this directory must be relative to the Drupal installation directory and be accessible over the web. If the download method is set to private, this directory should not be accessible over the web. Changing this location will modify all download paths and may cause unexpected problems on an existing site.'), '#after_build' => array('system_check_directory'), ); @@ -1429,6 +1429,15 @@ function system_file_system_settings() { } /** + * Validate the submitted file handling form. + */ +function system_file_system_settings_validate($form, &$form_state) { + if (strpos($form_state['values']['file_directory_path'], 'files') === FALSE) { + form_set_error('file_directory_path', t("The file system path must contain the word 'files' somewhere on the path for correct 404 handling.")); + } +} + +/** * Form builder; Configure site image toolkit usage. * * @ingroup forms Index: sites/default/default.settings.php =================================================================== RCS file: /cvs/drupal/drupal/sites/default/default.settings.php,v retrieving revision 1.25 diff -u -F^f -r1.25 default.settings.php --- sites/default/default.settings.php 8 Jun 2009 05:00:12 -0000 1.25 +++ sites/default/default.settings.php 13 Jun 2009 21:02:48 -0000 @@ -330,3 +330,27 @@ # $conf['blocked_ips'] = array( # 'a.b.c.d', # ); + +/* + * + * 404 bypass: + * + * Bootstrapping Drupal is somewhat resource intensive since it involves loading + * a lot of PHP files, and many database queries. In order to reduce the load on + * web sites when handling 404s for media files, we stop very early in the bootstrap + * process and issue a 404. + * + */ +$extensions = "txt|png|gif|jpe?g|shtml?|css|js|ico|swf|flv|cgi|bat|pl|dll|exe|asp"; +# If you do not use aliases ending in htm/html replace the above line with the +# line below. You need to make similar changes in the FilesMatch section above +# and your settings.php file. +# +# $extensions = "txt|png|gif|jpe?g|s?html?|css|js|ico|swf|flv|cgi|bat|pl|dll|exe|asp"; +# +if (preg_match('/\.(' . $extensions . ')$/', $_SERVER['QUERY_STRING'])) { + header('HTTP/1.0 404 Not Found'); + print "404 Not Found

Not Found

The requested URL was not found on this server.

"; + exit(); +} +