Table of Contents
404 errors on static content will lead to the Magento bootstrap (
index.php) being loaded in place of content. Even with the fastest of stores, a call to
index.php can come at a minimum cost of
If you multiply that by the number of 404 elements on your page, it can really add up.
Configuring a 404 error page for static content
We still want dynamic 404's to hit Magento, but for any static content (eg. CSS/JS/images) - its much better to serve a plain placeholder HTML page than hit the Magento bootstrap needlessly.
- All you need to do is create a directory (which usually already exists on a Magento store) called
- Within this directory, create a file called
404.php. You can put whatever content within this file that you want; usually a simple "Not found!" with a link back to your main website is sufficient.
Then to test if your changes have worked, just visit your website and try and view a non-existent URL
The default Magento
404.php looks like this, which you can style with the respective
default template directory in the
./errors directory. This is a good mechanism and does not introduce too much overhead - and allows for easier deployment of custom 404 pages for different stores, but if you want an extremely lightweight version, use the pure PHP/HTML alternative below.
<?php require_once 'processor.php'; $processor = new Error_Processor(); $processor->process404();
Alternatively, if you want something simpler, you can use ordinary PHP/HTML to achieve the same result.
<?php header("HTTP/1.0 404 Not Found"); ?> <html> ... </html>
Configuring a 404 error page for dynamic content
At present, we still let all dynamic content hit Magento's bootstrap - as the server cannot distinguish what is or isn't a real URL.
But this doesn't mean that you should ignore 404 dynamic content. 404 pages for Magento are very costly; as the response is not cached by Magento - so each time someone hits a 404 page, it is consuming server resources.
It is a good idea to regularly review logs and add Nginx rewrite rules to redirect 404 content with a 302 or 301 status back to your homepage (or a suitable replacement page).
Finding 404 errors
Access either the load balancer or web server Kibana dashboard
Then use the search string