July 23, 2014

Quick & Dirty WordPress Fix: Redirect 404 to another URL

Below is a note I wrote on November 10, 2010 about how to do a redirect on your 404 page in WordPress.

Quick & Dirty WordPress Fix: Redirect 404 to another URLI’m in the process right now of setting up a WordPress “site” with only one page (a squeeze page) and I was having a difficult time getting the “404″ page to match my squeeze page. So, screw it. Let’s figure it out!

Plugins are cumbersome. This little ditty works great.

Open up a text editor and paste this into it:

              header(“Status: 301 Moved Permanently”);

header(“Location:URL you want to redirect to”);

?>

Make sure you change “URL you want to redirect to” to a valid URL on your site. It could be a sales page, a page full of helpful links, whatever.

Save the file as 404.php. Now, go to your FTP client, find in your Themes folder the 404.php file and rename it to something else (a-404.php, for example). Then,

Upload the 404.php file you created to your Themes folder.

Grab a cold beverage! You’ve just redirected ANY 404 error page to whatever you placed in that code.

It could be your home page, a custom squeeze page, or a page off the site. It’s your choice.