diff --git a/core/lib/Drupal/Core/ExceptionController.php b/core/lib/Drupal/Core/ExceptionController.php index d08e1cf8f155ee26f578d61b5c1090b02c323cfb..352ffeac9d22d531556e2e2cffa4498da15d28fb 100644 --- a/core/lib/Drupal/Core/ExceptionController.php +++ b/core/lib/Drupal/Core/ExceptionController.php @@ -156,11 +156,13 @@ public function on404Html(FlattenException $exception, Request $request) { watchdog('page not found', check_plain($request->attributes->get('system_path')), NULL, WATCHDOG_WARNING); // Check for and return a fast 404 page if configured. - $exclude_paths = variable_get('404_fast_paths_exclude', FALSE); - if ($exclude_paths && !preg_match($exclude_paths, $request->getPathInfo())) { - $fast_paths = variable_get('404_fast_paths', FALSE); + $config = config('system.fast_404'); + + $exclude_paths = $config->get('exclude_paths'); + if ($config->get('enabled') && $exclude_paths && !preg_match($exclude_paths, $request->getPathInfo())) { + $fast_paths = $config->get('paths'); if ($fast_paths && preg_match($fast_paths, $request->getPathInfo())) { - $fast_404_html = variable_get('404_fast_html', '404 Not Found

Not Found

The requested URL "@path" was not found on this server.

'); + $fast_404_html = $config->get('html'); $fast_404_html = strtr($fast_404_html, array('@path' => check_plain($request->getUri()))); return new Response($fast_404_html, 404); } diff --git a/core/modules/system/config/system.fast_404.yml b/core/modules/system/config/system.fast_404.yml new file mode 100644 index 0000000000000000000000000000000000000000..731c8bbcff5b63fbf89f87cc73f9099c25180e63 --- /dev/null +++ b/core/modules/system/config/system.fast_404.yml @@ -0,0 +1,4 @@ +enabled: '1' +paths: '/\.(?:txt|png|gif|jpe?g|css|js|ico|swf|flv|cgi|bat|pl|dll|exe|asp)$/i' +exclude_paths: '/\/(?:styles)\//' +html: '404 Not Found

Not Found

The requested URL "@path" was not found on this server.

' diff --git a/core/modules/system/system.install b/core/modules/system/system.install index 0b3bfef71876e7eaea124b30d2012b27fea1c623..ac70335cdd65d408bedb822a72836f2b2a5cbacc 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -2348,6 +2348,19 @@ function system_update_8043() { )); } +/** + * Moves system fast 404 settings from variable to config. + * + * @ingroup config_upgrade + */ +function system_update_8044() { + update_variables_to_config('system.fast_404', array( + '404_fast_html' => 'html', + '404_fast_paths' => 'paths', + '404_fast_paths_exclude' => 'exclude_paths', + )); +} + /** * @} End of "defgroup updates-7.x-to-8.x". * The next series of updates should start at 9000. diff --git a/sites/default/default.settings.php b/sites/default/default.settings.php index e0d69bd0aae73605ba7285fa89a740edfc469c37..8d123d261fe2403e751d26306afa34794f07d5e2 100644 --- a/sites/default/default.settings.php +++ b/sites/default/default.settings.php @@ -484,37 +484,19 @@ * * 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, + * - $conf['system.fast_404']['exclude_paths']: 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 + * - $conf['system.fast_404']['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. + * - $conf['system.fast_404']['html']: The html to return for simple 404 pages. * - * Add leading hash signs if you would like to disable this functionality. + * Remove the leading hash signs if you would like to alter this functionality. */ -$conf['404_fast_paths_exclude'] = '/\/(?:styles)\//'; -$conf['404_fast_paths'] = '/\.(?:txt|png|gif|jpe?g|css|js|ico|swf|flv|cgi|bat|pl|dll|exe|asp)$/i'; -$conf['404_fast_html'] = '404 Not Found

Not Found

The requested URL "@path" was not found on this server.

'; - -/** - * By default the page request process will return a fast 404 page for missing - * files if they match the regular expression set in '404_fast_paths' and not - * '404_fast_paths_exclude' above. 404 errors will simultaneously be logged in - * the Drupal system log. - * - * You can choose to return a fast 404 page earlier for missing pages (as soon - * as settings.php is loaded) by uncommenting the line below. This speeds up - * server response time when loading 404 error pages and prevents the 404 error - * from being logged in the Drupal system log. In order to prevent valid pages - * such as image styles and other generated content that may match the - * '404_fast_html' regular expression from returning 404 errors, it is necessary - * to add them to the '404_fast_paths_exclude' regular expression above. Make - * sure that you understand the effects of this feature before uncommenting the - * line below. - */ -# drupal_fast_404(); +#$conf['system.fast_404']['exclude_paths'] = '/\/(?:styles)\//'; +#$conf['system.fast_404']['paths'] = '/\.(?:txt|png|gif|jpe?g|css|js|ico|swf|flv|cgi|bat|pl|dll|exe|asp)$/i'; +#$conf['system.fast_404']['html'] = '404 Not Found

Not Found

The requested URL "@path" was not found on this server.

'; /** * External access proxy settings: