How to redirect 404 error to custom page.
Suppose you had initially a folder /gallery/ in your website, but after sometime you changed name from gallery to /products/ and your old visitor remember your web page name or he found link to /gallery somewhere, He will come to your site with link www.yoursite.com/gallery/ but this directory and files inside this directory does not exist in this server cause we have changed it’s name to other directory name. This is situation when Server produce an error 404 Not found error. Which means what you are looking for in this site does not exist or moved somewhere else.
404 Not found error can come with reason that page, or post or anything else does not found. Wrong url , wrong address to page inside a site produce this error.
How wordpress handle 404 Page not found?
As you know wordpress is a great CMS and that give ability to handle many things , 404 is also wordpress’s ability to handle 404 error. Cause when we do not setup 404 error page in our site that can waste our traffic and they don’t find any link on our site where they should go. WordPress have a 404.php inside its template directory where this situation is handled in wordpress.
So if you want to handle 404 error in wordpress you have to add or edit 404.php in your theme’s directory make sure you are doing this with active theme for testing. Here you can control the look of 404 error page for your wordpress site.
We should setup its solution cause 404 not found error can waste our traffic much.
How to handle 404 Not found in custom site?
Well if you are not using any CMS or any frameowrk then you have to consider adding 404 handling manually in your website. I will talk about Apache server here, cpanel. Well what you have to do first create a file and name it anything this is the file which we will show when 404 error occures. Put anything inside your file whatever you want links to other pages maybe sitemap or anything. Let’s say you have named your 404 error file as my_error.html remember you can use my_error.php as well depends what type of site you have and what you want.
Creating .htaccess file to handle 404 error.
Now create a new file in your notepad, put following code in your file and save this file with file type nothing and save with name .htaccess make sure your file name is not .htaccess.txt or anything else it should only .htaccess well once you have done that now put the following code in this file.
ErrorDocument 404 /my_error.html
In Above code we are saying for document error number 404 please dont’s show default error but redirect user to my_error.html page. Put this line in your .htaccess file and upload this file in your root directory /public_html usually.
If you want to study more about .htaccess errors handling please go to How to redirect your 404 error to custom page.
We are sorry that this post was not useful for you!
Let us improve this post!
Tell us how we can improve this post?