In this guide we are going to talk about better handling 404 page not found errors in WordPress. This can be a problem when the WordPress theme template is used for all 404 errors, running unnecessary PHP code and MySQL queries.
An HTTP 404 Not Found error means that the content you were trying to load could not be found on the server. This is a client-side error meaning that the page has been deleted or moved and the address was not updated or redirected.
When a visitor requests a file or page that doesn’t exist, WordPress displays a 404 not found page that can include, widgets, archived pages, links, a search form, etc. Now, these custom 404 error pages might look good and have some useful things on them, but when loaded it creates unnecessary PHP & MySQL queries using server resources it doesn’t really need to.
You can use the following tools to check for 404 pages on your website.
Enable Apache logging
To stop WordPress loading a custom 404 page for these file types we need to add the following to a .htaccess file and setup a 404 page for static content.
Add the following lines to the .htaccess file before, # BEGIN WordPress:
Create a .htaccess file, add the following to the top of the file
ErrorDocument 404 /404.html
Then create a simple 404.html page with 404 error not found message and upload to the root of your WordPress install.
Beware that some RSS readers may try to load a Favicon file/image (favicon.ico) the little square 16px X 16px image you will see if you bookmark a page. If this doesn’t exist, it will also create a 404 page. Since WordPress 4.3 these favicons can be added from the WordPress dashboard. So no excuse not to have one!
Apple devices do a similar thing as RSS readers, searching for files that might not actually exist. You could see lots of 404 errors in your logs for the following files, apple-touch-icon.png and apple-touch-icon-precomposed.png. Again the easiest way to handle these 404 errors is to create these files and place them in your WordPress root directory. You can find more information about these files on the iOS developers website
I’ve tried to cover most things in this guide, hopefully the above will help you fix any 404 errors on your WordPress site.