The 411 on 404s

by Chris K on August 1, 2010

The 404 – File Not Found error. Its the darkest corner of your website that you probably don’t encounter too often, but do you know how often others are getting them on your site? Odds are, you don’t. One way to increase visitors (and more importantly keep visitors) is to avoid the 404 error, or embrace it by planning for it. Part of development is to always test the ‘negative case’. The case in which you know your code will fail. The same holds true in URLS. What happens if someone goes to a page or URL that doesn’t exist on your site? Go ahead, try it…I’ll wait. – There, that wasn’t so hard was it? What did you find? For most of you using WordPress, it’ll be a standard 404 page that your theme is using. Not too bad, but how many people are actually seeing this, usually content-less, page? Let’s find out.

Finding the 404s

Most hosting providers will give you some sort of coarse statistics, but they don’t typically cover 404′s. To find this, we must manually look at the logs to get a better sense of the traffic seeing these unsightly errors. For this section, I’m working with a Linux based hosting environment in which I have SSH access.

Locate your log files
Mine happen to be in a folder named logs of my root hosting account. Your’s may be somewhere else but we need to get into that folder via a command line.

cd html/stats/logs

Locate lines in the logs with 404s
Once in this log files folder we’re going to use the Linux command ‘grep’ to search all files for the string ’404′.

grep 404 *.*

You will now see a large printout that contains many lines of stuff that looks like the following:

html/stats/logs/ex20100727000001-97.74.24.35.log:208.115.111.249 – - [26/Jul/2010:22:43:16 -0700] “GET www.chriskdesigns.com/2009/04/08/death-of-a-medium/ HTTP/1.1″ 404 16804 “-” “Mozilla/5.0 (com
patible; DotBot/1.1; http://www.dotnetdotcom.org/, crawler@dotnetdotcom.org)”

That’s a request to your site that ended in a 404 – File Not found. The important parts are:
The URL the person tried to visit

www.chriskdesigns.com/2009/04/08/death-of-a-medium/

The HTTP Request version and the result (a 404 here)

HTTP/1.1″ 404

So now I know that this page is missing…was I aware of this before? If you have been to my site before you might recognize this as a valid post called ‘Death of a Medium‘. So why the 404? I had changed my Permalink structure at one point in time. If someone links to your previous Permalink Structure, after you change it will result in a 404. This is why I suggest setting your Permalink structure upon setup, and not changing. I learned my lesson the hard way.

Why is it good to know these 404′s? If you have change anything about your Permalinks, spelling in a title after it’s published, or a tag/category has been removed, you can use your 404 errors to see where the problems are and possibly correct them with a .htaccess redirect.

The Solution

So now we know how to see our 404 errors, but how do we correct them? If you are using an Apache based web server, you can use a .htaccess file to redirect people accordingly. Here are a few common .htaccess redirects that I find useful for WordPress users.

Redirect from domain.com/blog to just domain.com

rewriterule ^previous-folder-name(.*)$ “http\:\/\/your-domain-here\/$1″ [R=301,L]

Modified a Post/Page Title (note: only pertains to what is after domain.com/

RewriteCond %{REQUEST_URI} /.*mispelled-url-without-domain.*$ [NC]
RewriteRule ^(.*)helicoper(.*)$ /$1correctly-spelled-url-without=domain$2 [R=301,L]

Monetize
Something else you can do with your 404 page is monetize it. I know, sounds a little odd but it’s becoming more common in this world of backlinks. If you blog on a specific topic or a series of topics, you can setup an Amazon Associates Store and paste that code into the 404.php file of your theme. This will allow you to possibly make some money from those missed pages, and hopefully keep your visitors engaged in your site.

Humor
One of my favorite use of the 404 is humor. Here’s an article that someone wrote, listing their favorite 100 examples of humor used in a 404 page.

{ 0 comments… add one now }

Leave a Comment

Previous post:

Next post: