WordPress error 404 redirect to homepage or anywhere else

Here is a simple way to have WordPress direct any WordPress 404 pages to your main page or anywhere else you like.

Simply edit your 404 theme file, (eg ./wp-content/themes/404.php) – every wordpress theme has a 404.php file.

Replace all lines of code with the following:

   header("Status: 301 Moved Permanently");

However this will NOT redirect a non wordpress page (eg. www.yoursite.com/blah3333/) . For this, you need add an .htaccess file to your root web folder with the following code:

ErrorDocument 404 /index.php

I am not sure if the above .htaccess code would work on Windows based servers.