Fast 404 can be enabled for performance improvements under advanced settings in the settings.php file, see https://www.drupal.org/node/76824.

The discussion noted that enabling fast 404 will break image styles and added styles to the path exceptions. However, it did not include any documentation or information that fast 404 will break the default inline images if private download method is used.

I propose to either

  1. Add documentation about images and private download method
  2. Better: to include the default path in the exceptions such as $conf['404_fast_paths_exclude'] = '/\/(?:styles)|(?:system\/files)\//';

This would ensure that core functionality continues to work if fast 404 is enabled with just default settings.

Comments

jhodgdon’s picture

Project: Drupal core » Documentation
Version: 7.34 »
Component: documentation » Missing documentation

That sounds like a reasonable thing to add to the documentation. Feel free to edit the page -- it is part of the Community Documentation. Moving this to the Documentation issue queue in case someone else wants to work on it.

jelo’s picture

Should we just have it in d.o or as part of the settings file itself? Right now it reads:

/**
 * Fast 404 pages:
 *
 * Drupal can generate fully themed 404 pages. However, some of these responses
 * are for images or other resource files that are not displayed to the user.
 * This can waste bandwidth, and also generate server load.
 *
 * The options below return a simple, fast 404 page for URLs matching a
 * specific pattern:
 * - 404_fast_paths_exclude: A regular expression to match paths to exclude,
 *   such as images generated by image styles, or dynamically-resized images.
 *   If you need to add more paths, you can add '|path' to the expression.
 * - 404_fast_paths: A regular expression to match paths that should return a
 *   simple 404 page, rather than the fully themed 404 page. If you don't have
 *   any aliases ending in htm or html you can add '|s?html?' to the expression.
 * - 404_fast_html: The html to return for simple 404 pages.
 *
 * Add leading hash signs if you would like to disable this functionality.
 */

How about adjusting this paragraph to:
404_fast_paths_exclude: A regular expression to match paths to exclude, such as images generated by image styles, or dynamically-resized images. If you need to add more paths, you can add '|path' to the expression. If you use private file download method and expect images to display inline, you will have to add "|(?:system\/files)" to the excluded paths.

jhodgdon’s picture

Hm. Yeah, maybe it should be added to the settings.php file... feel free to move this back to Drupal Core. If you do, set the version to 8.0.x please, since our policy is to fix API documentation in Drupal 8 first, then backport to D7.

jelo’s picture

Sorry. It might be too early in the morning for me, but I seem unable to find the appropriate project to change it back to in the autocomplete. @jhodgdon: can you set it back?

If we open this discussion, I think it would be great to evaluate if it should be only in the settings file as documentation or by default be added to the path exclusions.

Thanks, J.

jhodgdon’s picture

Title: Fast 404 and private image files » Document (or set up?) fast 404 settings for private image files
Project: Documentation » Drupal core
Version: » 8.0.x-dev
Component: Missing documentation » base system
Issue tags: +settings.php

There we go...

michaellenahan’s picture

If we open this discussion, I think it would be great to evaluate if it should be only in the settings file as documentation or by default be added to the path exclusions.

+1 to having the private file system added by default to the path exclusions.

A note in the docblock comment about the private file system would help as well.

It took me a very long time today to work out why my images weren't showing after I enabled the private file system. Everything worked fine on the stage server, but on the live server I was getting 404s.

Until I came across this page I wasn't aware of fast 404, now I guess I've learned my lesson :), but having the private file system excluded by default seems like a "sane default" to me. (Unless there are downsides I haven't considered yet).

jelo’s picture

Welcome to the club. It took me a long time to figure this out. As a minimum I would suggest to enter the documentation in the file itself. I guess this could be done as a patch submission? I am not setup for patch submissions yet. Michael, would you be able to submit the text change as a patch submission?

404_fast_paths_exclude: A regular expression to match paths to exclude, such as images generated by image styles, or dynamically-resized images. If you need to add more paths, you can add '|path' to the expression. If you use private file download method and expect images to display inline, you will have to add "|(?:system\/files)" to the excluded paths.

Does it need more feedback from the community to change the default or should that be submitted as a patch as well?

michaellenahan’s picture

StatusFileSize
new920 bytes

@jelo --- with pleasure! Here's the patch.

I agree that documenting the issue is a good minimum step.

michaellenahan’s picture

Component: base system » documentation
Status: Active » Needs review
jhodgdon’s picture

Docs look great! However I think we should really consider adding this to the defaults too?

jhodgdon’s picture

Component: documentation » base system
Status: Needs review » Needs work

In which case we should move this to the "base system" component as it is not just docs.

jelo’s picture

I am all for adding this to the defaults. I don't think it makes sense to break inline images in private file download mode purposefully.

Michael, based on Jennifer's suggestion, could you roll another patch that adjusts the default exclusion path to
$conf['404_fast_paths_exclude'] = '/\/(?:styles)|(?:system\/files)\//';

We then may have to change the text to read as follows:
* - 404_fast_paths_exclude: A regular expression to match paths to exclude,
* such as images generated by image styles, the default path to private file downloads to enable inline image display, or dynamically-resized images.
* If you need to add more paths, you can add '|path' to the expression.

jhodgdon’s picture

That seems like a good course of action to me, thanks!

michaellenahan’s picture

StatusFileSize
new1.44 KB

Hi, sorry it took a while to get round to this. Here is the patch: I rewrote the docblock comment slightly as well.

jhodgdon’s picture

This looks good to me, thanks! However the suggestions in #12 are not all there, and they seem like good additions to the documentation?

michaellenahan’s picture

However the suggestions in #12 are not all there

Well, I re-wrote the suggestion in #12 slightly, so that it includes the sentence:
"The default pattern provided below also excludes the private file system."

For me, that covers the intention in #12. I made it a separate sentence because I thought that would be easier to read. It also makes it easier to understand that there are two parts to the exclusion - firstly for image styles, then secondly for the private file system.

 * The options below return a simple, fast 404 page for URLs matching a
 * specific pattern:
 * - $conf['system.performance']['fast_404']['exclude_paths']: A regular
 *   expression to match paths to exclude, such as images generated by image
 *   styles, or dynamically-resized images. The default pattern provided below
 *   also excludes the private file system. If you need to add more paths, you
 *   can add '|path' to the expression.

...

# $config['system.performance']['fast_404']['exclude_paths'] = '/\/(?:styles)|(?:system\/files)\//';
jhodgdon’s picture

Status: Needs work » Reviewed & tested by the community

Oh, right! Sorry about that. Must have been Monday. I think this is good then!

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 6475b82 and pushed to 8.0.x. Thanks!

  • alexpott committed 6475b82 on 8.0.x
    Issue #2455057 by michaellenahan, jhodgdon, jelo: Document (or set up?)...
michaellenahan’s picture

Version: 8.0.x-dev » 7.x-dev
Status: Fixed » Needs review
StatusFileSize
new1.42 KB

Here's the Drupal 7 backport.

jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs backport to D7

Thanks! Yes, backporting this seems reasonable.

David_Rothstein’s picture

Title: Document (or set up?) fast 404 settings for private image files » Fix fast 404 settings for private image files
Status: Reviewed & tested by the community » Fixed
Issue tags: +7.40 release notes

Hm, so as far as I can see this is only needed by sites that put the drupal_fast_404() line in settings.php. For other sites, the current setting would actually be preferable and more performant.

However, we already excludes 'styles' for all sites, and if you're using private files the performance gain from fast 404 is less important anyway, so yeah, let's do this and then maybe see if we can follow up with another issue to prevent Drupal from excluding anything except when drupal_fast_404() is actually called from settings.php.

Committed to 7.x - thanks!

  • David_Rothstein committed 6e6c3db on 7.x
    Issue #2455057 by michaellenahan, jhodgdon, jelo: Fix fast 404 settings...
David_Rothstein’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.