diff options
Diffstat (limited to 'includes')
-rw-r--r-- | includes/bootstrap.inc | 28 | ||||
-rw-r--r-- | includes/common.inc | 5 |
2 files changed, 32 insertions, 1 deletions
diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc index 1fe8c1435..39c1b0852 100644 --- a/includes/bootstrap.inc +++ b/includes/bootstrap.inc @@ -2403,6 +2403,34 @@ function drupal_maintenance_theme() { } /** + * Returns a simple 404 Not Found page. + * + * If fast 404 pages are enabled, and this is a matching page then print a + * simple 404 page and exit. + * + * 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. + * + * Paths to dynamically-generated content, such as image styles, should also be + * accounted for in this function. + */ +function drupal_fast_404() { + $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', '<html xmlns="http://www.w3.org/1999/xhtml"><head><title>404 Not Found</title></head><body><h1>Not Found</h1><p>The requested URL "@path" was not found on this server.</p></body></html>'); + // Replace @path in the variable with the page path. + print strtr($fast_404_html, array('@path' => check_plain(request_uri()))); + exit; + } + } +} + +/** * Return TRUE if a Drupal installation is currently being attempted. */ function drupal_installation_attempted() { diff --git a/includes/common.inc b/includes/common.inc index 3b32a2083..da0340b3f 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -2476,6 +2476,9 @@ function drupal_deliver_html_page($page_callback_result) { watchdog('page not found', check_plain($_GET['q']), NULL, WATCHDOG_WARNING); + // Check for and return a fast 404 page if configured. + drupal_fast_404(); + // Keep old path for reference, and to allow forms to redirect to it. if (!isset($_GET['destination'])) { $_GET['destination'] = $_GET['q']; @@ -2492,7 +2495,7 @@ function drupal_deliver_html_page($page_callback_result) { if (empty($return) || $return == MENU_NOT_FOUND || $return == MENU_ACCESS_DENIED) { // Standard 404 handler. drupal_set_title(t('Page not found')); - $return = t('The requested page could not be found.'); + $return = t('The requested page "@path" could not be found.', array('@path' => request_uri())); } drupal_set_page_content($return); |