By simply adding a file called 404.php into your WordPress theme directly you can quite easily create and customize the page shown when a visitor tries to access something which isn’t there. But what if you wanted to automatically redirect this user to your front page (or some other page on your site) instead of showing them a 404 error page? Well, the solution is quite simple.
If you place the above code snippet and nothing else into a file called 404.php within the root of your WordPress theme directory then whenever someone tries to view a page which doesn’t exist they will be automatically and instantly redirected to your sites homepage.
Be careful though, you need to make sure that there are no spaces, empty lines or any other type of output (including HTML) above those two lines of code. If there are then you’ll most likely get a PHP error complaining that the headers cannot be set as there has already been some output.
Of course you don’t necessarily have to redirect them to your front page. You could change it to redirect all 404 page not found requests to some other page on your site. For example, the following code snippet would redirect the visitor to your /about/ page.
It’s as simple as that. You’ve now redirected all 404 page not found requests to some other page on your site. Simple!Like(0) un-like(0)