A special Page 404 is used in situation when WordPress cannot find a particular page. This page should work fine by default – WordPress should automatically look for the 404.php web page when page from selected address doesn’t exist. But sometimes this could not work properly because web server can encounter a problem before WordPress is aware of it. To resolve this, you will have to configure your web server for custom 404 error handling. This will guarantee that your web server sends the visitor to your 404.php page template.
You must set your web server to use your custom error files. For this you need to edit the .htaccess file in the main directory (root of your site, where index.php file is located) of your WordPress installation. If you don’t have an .htaccess file, you must create it. To create a .htaccess file you can just create a new TXT file and change its name to .htaccess (no name plus .htaccess file extension).
Now you must just edit .htaccess file and add the following line:
ErrorDocument 404 /index.php?error=404
This will ensure that the server finds your 404 page.
The URL /index.php is server root-relative (the forward slash begins with the root folder of your site). This means that you must put here a full URL path. For example, if your site is located in a subfolder or subdirectory of your site’s root folder named ‘foldername’, the line you add to your .htaccess file should be:
ErrorDocument 404 /foldername/index.php?error=404