2

D7.9 introduced 404 fast paths which don't fully bootstrap drupal on 404's for certain file types if it's enabled, thus saving some bandwidth / computation. More info is available here: http://drupal.org/node/1296384

By default this excludes only certain file types such as .jpg, .txt., etc., looks like this:

$conf['404_fast_paths_exclude'] = '/\/(?:styles)\//';
$conf['404_fast_paths'] = '/\.(?:txt|png|gif|jpeg|css|js|ico|swf|flv|cgi|bat|pl|dll|exe|asp)$/i';

I want to use this for all paths. Are there any repercussions to that?

I tried changing it to

$conf['404_fast_paths'] = '/*$/i'; 

However, this returns a warning:

Warning: preg_match() Compilation failed: nothing to repeat at offset 0 in drupal_fast_404() (line 2484 of /cms/main/includes/bootstrap.inc).

So what should the syntax look like up there to both work and not generate a warning?

Alternatively, if there isn't a solution to this specific question, is there a way I can speed up 404's for all Drupal pages, would it better to use the Fast 404 contributed module for instance?

0

2 Answers 2

5

You used "/*$/i" as regular expression, but there is nothing before the asterisk; in other words, you are not saying what can be repeated zero or more times. Valid regular expressions expressions such as "/.*/i", "/[a-zA-Z]*/i", "/(foo|bar)*/i".

drupal_fast_404() is called by drupal_deliver_html_page() when the result of menu_execute_active_handler() is MENU_NOT_FOUND, which means Drupal is asked to look for a path without any menu callback associated. drupal_fast_404() first checks that $_GET['q'] doesn't match the regular expression contained in the "404_fast_paths_exclude" Drupal variable; if it doesn't match that regular expression, then it checks $_GET['q'] matches the regular expression contained in the "404_fast_paths" Drupal variable. The default value for that variable is '/\.(?:txt|png|gif|jpe?g|css|js|ico|swf|flv|cgi|bat|pl|dll|exe|asp)$/i' which means the fast 404 page is returned when the request is for a file with the following extensions:

  • .txt
  • .png, .gif, .jpg, .jpeg
  • .css, .js
  • .ico, .swf, .flv
  • .cgi, .bat, .pl, .dll, .exe, .asp

If you want the fast 404 pages be used in any case, I would not touch the value of the "404_fast_paths_exclude" Drupal variable, and change the content of the "404_fast_paths" Drupal variable to '/.*/i', which would match any path that causes a 404 error, excluding the ones containing "styles."

1
  • Upvoted you, although it should be noted that this doesn't work in the context of Drupal and what I am trying to accomplish, which is why it is a Drupal question. If one uses this syntax and drupal_fast_404() called in settings.php it will return all pages as 404 Not Found. However, commenting out the drupal_fast_404() call there along with using this syntax does work (something I figured out after asking the question). Commented Feb 14, 2012 at 6:55
2

To exclude additional paths, this seems to work:

$conf['404_fast_paths_exclude'] = '/\/(?:styles)\/|robots\.txt|(?:another-dir)\//';

where 'another-dir' can be the child of a longer path (as is styles).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.