wordpress 404.php redirect to home

  1. Navigate to your WordPress theme directory.

  2. Locate the "404.php" file within your theme directory.

  3. Open the "404.php" file using a text editor.

  4. Add the following code at the beginning of the file:

<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: " . home_url());
exit();
?>
  1. Save the changes to the "404.php" file.

  2. Upload the modified "404.php" file back to your WordPress theme directory, replacing the existing file.

  3. The 404 error page will now redirect to the home page.