diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc index 0ca3bfa..56ebabe 100644 --- a/includes/bootstrap.inc +++ b/includes/bootstrap.inc @@ -2237,15 +2237,21 @@ function drupal_maintenance_theme() { * 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. + * + * Paths to dynamically-generated content, such as image styles, should also be + * accounted for in this function. */ function drupal_fast_404() { - $fast_paths = variable_get('404_fast_paths', FALSE); - if ($fast_paths && preg_match($fast_paths, $_GET['q'])) { - drupal_add_http_header('Status', '404 Not Found'); - $fast_404_html = variable_get('404_fast_html', '404 Not Found

Not Found

The requested URL "@path" was not found on this server.

'); - // Replace @path in the variable with the page path. - print strtr($fast_404_html, array('@path' => check_plain(request_uri()))); - exit; + $exclude_paths = variable_get('404_fast_paths_exclude', FALSE); + if ($exclude_paths && !preg_match($exclude_paths, $_GET['q'])) { + $fast_paths = variable_get('404_fast_paths', FALSE); + if ($fast_paths && preg_match($fast_paths, $_GET['q'])) { + drupal_add_http_header('Status', '404 Not Found'); + $fast_404_html = variable_get('404_fast_html', '404 Not Found

Not Found

The requested URL "@path" was not found on this server.

'); + // Replace @path in the variable with the page path. + print strtr($fast_404_html, array('@path' => check_plain(request_uri()))); + exit; + } } } diff --git a/sites/default/default.settings.php b/sites/default/default.settings.php index 2c08441..7fe843c 100644 --- a/sites/default/default.settings.php +++ b/sites/default/default.settings.php @@ -436,6 +436,9 @@ ini_set('session.cookie_lifetime', 2000000); * * The options below return a simple, fast 404 page for URLs matching a * specific pattern: + * - 404_fast_paths_exclude: A regular expression to match paths to exclude, + * such as images generated by image styles, or dynamically-resized images. + * If you need to add more paths, you can add '|path' to the expression. * - 404_fast_paths: A regular expression to match paths that should return a * simple 404 page, rather than the fully themed 404 page. If you don't have * any aliases ending in htm or html you can add '|s?html?' to the expression. @@ -443,6 +446,7 @@ ini_set('session.cookie_lifetime', 2000000); * * Add leading hash signs if you would like to disable this functionality. */ +$conf['404_fast_paths_exclude'] = '/\b\/(styles)\/\b/'; $conf['404_fast_paths'] = '/\.(txt|png|gif|jpe?g|css|js|ico|swf|flv|cgi|bat|pl|dll|exe|asp)$/i'; $conf['404_fast_html'] = '404 Not Found

Not Found

The requested URL "@path" was not found on this server.

';