Fast_404 is Super Fast and Super Amazing. It is also very aggressive and
BE CAREFUL! TEST YOUR SITE THOROUGHLY AFTER ENABLING!
*NOTE, THIS ONLY CHECKS STATIC FILES AND NOT DRUPAL PATHS*
(no settings.php modifications needed)
Step 1. Upload the module to your standard modules location (usually
Step 2. Enable the module in your modules page
Step 1. Upload the module to your standard modules location (usually
Step 2. Place the code at the bottom of this file into your settings.php file
Step 3. Optionally, modify the include_once path if you did not put the module
Step 4. Enable the module in your modules page
-- Getting Extra Speed out of the Advanced Install --
-- 高级安装得到的速度好处 --
#1) Check extensions from settings.php, not hook_boot.
This method is faster as it checks for missing static files at bootstrap
stage 3 rather than 7 when the module's hook_boot() is called. Also, if you
are using aggressive or external caching, hook_boot is skipped, so you will
*need* to do this.
To enable this functionality, uncomment the line below near the bottom of the
#2) Enable Drupal path checking
This checks to see if the URL you being visited actually corresponds to a
real page in Drupal. This feature has 2 switches:
a). Global switch to turn this checking on and off:
$conf['fast_404_path_check'] = FALSE;
b). To perform this check in settings.php for the same reasons as listed
above for the static file checking uncomment the following line in the
#3) Give the static file checking a kick in the pants!
Static file checking does require you to keep an eye on the extension list
as well as a bit of extra work with the preg_match (OK, a very small amount).
Optionally, you can use whitelisting rather than blacklisting. To turn this
on alter this setting in the settings.php:
$conf['fast_404_url_whitelisting'] = FALSE;
This setting requires you to do some serious testing to ensure your site's
pages are all still loading. Also make sure this list is accurate for your
$conf['fast_404_whitelist'] = array('index.php', 'rss.xml', 'install.php', 'cron.php', 'update.php', 'xmlrpc.php');
#4) Disallow imagecache file creation for anonymous users (NEW!)
Normally the module skips out if imagecache is in the URL to the static file.
There are times when you may not want this (it would be pretty easy for
someone to take down your site by simply hammering you with URLs with
imagecache in them.
In an ideal situation, your logged in users should have verified the pages
are loading correctly when they create them, so any needed imagecache images
are already made. This new setting will make it so that imagecache URLs are
not excluded and fall under the same static file rules as non-imagecache
URLs. Set to false to enable this new feature.
$conf['fast_404_allow_anon_imagecache'] = TRUE;
#5) Prevent conflicts with other modules (NEW!)
Some performance modules create paths to files which don't exist on disk.
These modules conflict with fast_404. To workaround this limitation, you
can whitelist the URL fragments used by these modules.
For example if you are using the CDN module and have the far future date
feature enabled add the following configuration:
$conf['fast_404_string_whitelisting'] = array('cdn/farfuture');
If you are using AdvAgg you can use this:
$conf['fast_404_string_whitelisting'] = array('/advagg_');
--- Copy the code below into the BOTTOM of your settings.php. ---
--- If you are using cacherouter, put this above cacherouter. ---
/** * Fast 404 settings: * * Fast 404 will do two separate types of 404 checking. * * The first is to check for URLs which appear to be files or images. If Drupal * is handling these items, then they were not found in the file system and are * a 404. * * The second is to check whether or not the URL exists in Drupal by checking * with the menu router, aliases and redirects. If the page does not exist, we * will server a fast 404 error and exit. */ # Load the fast_404.inc file. This is needed if you wish to do extension # checking in settings.php. include_once('./sites/all/modules/fast_404/fast_404.inc'); # Disallowed extensions. Any extension in here will not be served by Drupal and # will get a fast 404. # Default extension list, this is considered safe and is even in queue for # Drupal 8 (see: http://drupal.org/node/76824). $conf['fast_404_exts'] = '/^(?!robots).*\.(txt|png|gif|jpe?g|css|js|ico|swf|flv|cgi|bat|pl|dll|exe|asp)$/i'; # If you use a private file system use the conf variable below and change the # 'sites/default/private' to your actual private files path # $conf['fast_404_exts'] = '/^(?!robots)^(?!sites\/default\/private).*\.(txt|png|gif|jpe?g|css|js|ico|swf|flv|cgi|bat|pl|dll|exe|asp)$/i'; # If you are using the Advanced Help module, the following config may be used # to allow paths starting with 'help'. $conf['fast_404_exts'] = '/^(?!help\/)(?!robots).*\.(txt|png|gif|jpe?g|css|js|ico|swf|flv|cgi|bat|pl|dll|exe|asp)$/'; # If you would prefer a stronger version of NO then return a 410 instead of a # 404. This informs clients that not only is the resource currently not present # but that it is not coming back and kindly do not ask again for it. # Reference: http://en.wikipedia.org/wiki/List_of_HTTP_status_codes # $conf['fast_404_return_gone'] = TRUE; # Allow anonymous users to hit URLs containing 'imagecache' even if the file # does not exist. TRUE is default behavior. If you know all imagecache # variations are already made set this to FALSE. $conf['fast_404_allow_anon_imagecache'] = TRUE; # If you use FastCGI, uncomment this line to send the type of header it needs. # Reference: http://php.net/manual/en/function.header.php # $conf['fast_404_HTTP_status_method'] = 'FastCGI'; # Extension list requiring whitelisting to be activated **If you use this # without whitelisting enabled your site will not load! //$conf['fast_404_exts'] = '/\.(txt|png|gif|jpe?g|css|js|ico|swf|flv|cgi|bat|pl|dll|exe|asp|php|html?|xml)$/i'; # Default fast 404 error message. $conf['fast_404_html'] = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd"><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. (Fast 404)</p></body></html>'; # Check paths during bootstrap and see if they are legitimate. $conf['fast_404_path_check'] = FALSE; $conf['fast_404_path_check'] = TRUE; # If enabled, you may add extensions such as xml and php to the # $conf['fast_404_exts'] above. BE CAREFUL with this setting as some modules # use their own php files and you need to be certain they do not bootstrap # Drupal. If they do, you will need to whitelist them too. $conf['fast_404_url_whitelisting'] = FALSE; # Array of whitelisted files/urls. Used if whitelisting is set to TRUE. $conf['fast_404_whitelist'] = array('index.php', 'rss.xml', 'install.php', 'cron.php', 'update.php', 'xmlrpc.php'); # Array of whitelisted URL fragment strings that conflict with fast_404. $conf['fast_404_string_whitelisting'] = array('cdn/farfuture', '/advagg_'); # By default we will show a super plain 404, because usually errors like this are shown to browsers who only look at the headers. # However, some cases (usually when checking paths for Drupal pages) you may want to show a regular 404 error. In this case you can # specify a URL to another page and it will be read and displayed (it can't be redirected to because we have to give a 30x header to # do that. This page needs to be in your docroot. #$conf['fast_404_HTML_error_page'] = './my_page.html'; # By default the custom 404 page is only loaded for path checking. Load it for all 404s with the below option set to TRUE $conf['fast_404_HTML_error_all_paths'] = FALSE; # Call the extension checking now. This will skip any logging of 404s. # Extension checking is safe to do from settings.php. There are many # examples of this on Drupal.org. //fast_404_ext_check(); fast_404_ext_check(); # Path checking. USE AT YOUR OWN RISK (only works with MySQL). # Path checking at this phase is more dangerous, but faster. Normally # Fast_404 will check paths during Drupal boostrap via hook_boot. Checking # paths here is faster, but trickier as the Drupal database connections have # not yet been made and the module must make a separate DB connection. Under # most configurations this DB connection will be reused by Drupal so there # is no waste. # While this setting finds 404s faster, it adds a bit more load time to # regular pages, so only use if you are spending too much CPU/Memory/DB on # 404s and the trade-off is worth it. # This setting will deliver 404s with less than 2MB of RAM. //fast_404_path_check(); fast_404_path_check();