Drupal: fast 404s

Ein Tip von 2bits für 404s von fehlenden statischen Dateien. Fügt man folgnden Code an das Ende der settings.php wird nicht ein kompletter bootstrap bei fehlenden Files durchgeführt:

// List of extensions for static files
$exts = 'txt|png|gif|jpe?g|shtml?|css|js|ico|swf|flv|cgi|bat|pl|dll|exe|asp|xml';

// It is not an imagecache path, which we allow to go through Drupal
if (!strpos($_SERVER['QUERY_STRING'], 'imagecache')) {
 // It is not our main feed page
 if ($_SERVER['QUERY_STRING'] != 'rss.xml') {
 // Is it a static file?
 if (preg_match('/\.(' . $exts . ')$/', $_SERVER['QUERY_STRING']))
 // Just send a 404 right now ...
 {
 header('HTTP/1.0 404 Not Found');
 print '<html>';
 print '<head><title>404 Not Found</title></head>';
 print '<body><h1>Not Found</h1>';
 print '<p>The requested URL was not found on this server.</p>';
 print '</body></html>';
 exit();
 }
 }
}

Possibly related posts (automatically generated)