drupal_fast_404

7 bootstrap.inc drupal_fast_404()
8 bootstrap.inc drupal_fast_404()

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.

1 call to drupal_fast_404()

File

includes/bootstrap.inc, line 2503
Functions that need to be loaded on every Drupal request.

Code

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;
    }
  }
}
Login or register to post comments