About a couple of months ago I put my entire website into WordPress…now every page on this website is actually a WordPress blog post. This makes it very easy to add new content and modify existing content, and it is also good for SEO (it is already manifest in my stats). Besides, whenever I want to change the layout/design, I simply have to create a new WordPress theme, and then activate it using the WordPress control panel/admin area.
After a few days I noticed that my 404 page was not working. Wondering what’s a 404 page? 404 is the error number that is generated when a visitor comes to your website using a link that does not exist on your website. For instance, on my website, if you click on a link http://credible-content.com/doesntexist/ you will be redirected to http://credible-content.com/404-page/ because "doesntexist" doesn’t exist on my website.
On normal websites you can add the following line in your .htaccess file:
ErrorDocument 404 http://credible-content.com/404-page/
You need to store your .htaccess file in the root folder I guess. But this doesn’t work if you are managing your website with WordPress; somehow it doesn’t redirect the page using .htaccess file. After some research I found that WordPress uses its own 404.php file to display the "page not found" page and you have to store this file in the folder where you’ve stored all your theme files, like /blog-url/wp-content/themes/your-theme-folder/404.php.
But what if you want to display a page or blog post that you’ve already created, if someone comes on a non-existent page? It’s very simple. Delete whatever you have in your 404.php file and instead, have this php line inserted:
<?php header("Location: /404-page/"); ?>
Please remember that /404-page/ is something what I’ve created for my website; you may have something else.