404 Page

How to Redirect 404 Not Found Page Using .htaccess

Recently, I moving one of my website from WordPress CMS to normal static html. I found out that there are too many 404 not found errors.

One of the solutions is to redirect it to more meaningful page, especially the Homepage. Although some people may argue, the usefulness of the redirects. However, I prefer to do so on some of my websites.

To do this I need to edit “.htaccess” which located at the root folder of the particular website. If you are unable to see the file, make sure you allow to view hidden files since “.htaccess” is a hidden file. If it still not there, then create it.

The following procedure, guides on how to redirect.

  1. If you are using cPanel, log into front-end and click on “File Manager” application. Make sure you enable the hidden file viewers.
  2. Go to the root folder of the website & edit or create “.htaccess” file.
  3. Add the following code & replace YOURURL with the URL where you want the error 404 page redirected to.
  4. Click save & you are done.
ErrorDocument 404 http://YOURURL

How to Redirect WordPress 404 Not Found Page to Homepage

Most of the time, WordPress 404 not found page does not provide much valuable information to the visitors who stuck at that page. One of the solutions is to redirect it to more meaningful page, especially the Homepage.

Although some people may argue, the usefulness of the redirects. However, I prefer to do so on some of my websites. The following procedure, guides on how to redirect.

  1. In WordPress admin area, head up to “Appearence” & click on “Editor”
  2. On the right hand site, click on file “404.php”. File description is “404 Template”.
  3. If the file does not exist, create one. If it does replace it with the following code & click save.
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: ".get_bloginfo('url'));
exit();
?>

However, if you want to redirect to other pages, use the following code but remember to replace “YOURPAGEURL” with your page URL. Make sure you leave the open & close quotes.

<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: ".get_bloginfo('url')."YOURPAGEURL");
exit();
?>