No 404 on WordPress Blogs!

If you are like me, and you try out different things on your WordPress blogs, you are sometimes in a situation where you have a ton of redirects to do.

You could be changing permalink structure on an established blog, or you could be moving to new hosts, forgetting some posts or tags.

Whatever the reason, you have a few options regarding 404 errors. Not sure what that is?  What are 404 errors?

A 404 error is what occurs if you go to a post/page/tag/whatever, that no longer exists. Many WordPress Themes have a separate page for this situation, and you can tweak it accordingly. There is a problem, however, the link will still return a 404, and this will affect your ranking in the search engines.

Going through these manually and setting up redirects in your .htaccess or using a plugin such as Redirection (one of my favorite SEO WordPress Plugins) takes time, and you have to know what you are doing.

If you just want to make sure there are no leaking holes in your WordPress blog, that looses linkjuice for you, there is a very quick way for you to take care of this.

  • Go to the folder of your WordPress Theme
  • Does it have a file named “404.php”? If not, create one, if it does, consider using below code instead.
  • Open up the 404.php and fill in the following code:
<?php $url=bloginfo('url'); header("Location: $url ",TRUE,301); ?>

So, what is going on? Whenever a 404 error occurs, WordPress first tries to look in the WordPress Theme’s folder, to look for a 404.php file. If that does not exist, a 404 error is returned, and then an error page is displayed. This varies based on your server/host and .htaccess.

You can also read automatic 301 redirects for spam pages.

Notes:

This is the quick, fast and easy way to make a 301 redirect on all 404 pages on your WordPress blog. However, it does not register anything, and it only directs the “linkjuice” from the sites linking to you to your front page. If you wish to direct that linkjuice to some other place, you will have to edit the code.

Have fun 🙂

7 Comments

  1. Scriptdaily on 21/11/2009 at 07:00

    Thanks it’s great, i will try this

  2. Kosta on 21/11/2009 at 20:39

    Very slick !

    Tks

    Kosta

  3. Dave on 26/11/2009 at 17:04

    Hmm…

    Did you guys get it working?

    I tired adding that code but it didnt’ work.

    I tried replacing the 404 page’s code with this but it fails to redirect and gives an error message.

    I tried adding it to the existing code and it also failed.

    I am pretty sure you’ve left some of the code out, such as the opening tag: ‘<?'

    Even adding that tag to the code won't get it to work though.

    Do I have to change any of that code to match the URL of my blog?

    I don't understand what I am doing wrong.

    Any additional info would be helpful thanks.

  4. Dave on 26/11/2009 at 17:24

    OK, after a quick search I found a much easier way to do this. Simply add this to your 404 page:

    and change the URL to your blog’s front page.

    Simple and it works.

  5. Dave on 26/11/2009 at 16:56

    I think you left out the opening ‘<?' tag.

    That code you gave won't work without it.

    Even if I add that tag it still doesn't work.

    Can you please post the full code needed to get this to redirect?

    Thanks

  6. cleverplugins.com on 27/11/2009 at 04:14

    Hi Dave

    I think your comment included some code that was cut after you commented?

  7. Danmark Bag Facaden on 15/12/2009 at 06:07

    on my blog i have my 404 error pages pointing to a overview over random feeds ( NyhedsLinks ), thats very usefull imo…

Leave a Comment





Cleverplugins.com Newsletter

Articles about how to improve your WordPress website, how to get more traffic and most importantly more customers.

Subscribe

Something went wrong. Please check your entries and try again.