How to redirect 404 to homepage in wordpress

Want to redirect 404 error page to your homepage in wordpress? Here is how

Login to your wordpress admin page http://website.com/wp-admin/
Go to “Apperarance” -> “Editor” -> 404.php

If your theme doesnt have 404.php page, create one under your theme directory wp-content/themes/themename/

Change or create your 404.php code to these

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

What those code does is to tell browswer that page has moved permantly with 301 error code, then redirect to your home page.

Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments