If a web server fails to handle a request or encounters an error before invoking
your PHP application, it falls back to its own default error pages, bypassing
Symfony's built-in pages or your custom error pages. You can reproduce this
scenario on many websites by requesting the path %
(e.g., https://example.com/%
).
In Symfony 7.3, we've added a new error:dump
command which lets you export
your error pages as static HTML files. This ensures users always see your defined
pages and boosts performance by serving errors directly from the web server
without booting your application:
1 2 3 4 5 6 7
# the first argument is the directory where the HTML files will be stored
# (they are named 400.html, 401.html, 402.html, .., 510.html, 511.html)
$ APP_ENV=prod php bin/console error:dump var/cache/prod/error_pages/
# by default, it generates the pages of all 4xx and 5xx errors, but you can
# pass a list of HTTP status codes to generate only those pages
$ APP_ENV=prod php bin/console error:dump var/cache/prod/error_pages/ 401 403 404 500
Next, update your server configuration to use these HTML files for the relevant error status codes. Check the Symfony Docs example for nginx servers.