Michael Gray

Wordpress 2.0 Permalinks, Error Codes, and Google Sitemaps

Posted on May 6th, 2006
by Michael Gray in Blogs, Programming



So I’m working on using Wordpress as a CMS for a “static looking” site and so far I’m pretty happy (get the static front page plugin it saves oodles of time). I’ve learned to keep my hacks in the templates and out of the “program files”. I’ve also moved to using permalinks and have the structure set to this

/%category%/%postname%/

my htaccess is set up as follows


# BEGIN WordPress

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php

# END WordPress

The problem is wordpress has to get into ‘the loop‘ before it knows if example.com/foo/bar/ exists or not, and if it doesn’t exist it’s too late to rewrite the header with a ‘404 response code’. Sending a 200 response code when you realy should be sending a 404 can create some ‘false pages’ that get indexed but it also throws things off if you are using the sitemaps plugin to interface with Google Sitemaps. Sitemap validation requires a 404 error code be sent and they check for it (they had a problem a few months back and had to make that change). I temporarily turned it off to get past the check and then turned it back on. It’s a workaround and I’m not really thrilled with it. So how ’bout it any of you clever readers come across this problem yet ,if so have you figured out a solution you’d like to share?

Popularity: 9% [?]

Sphere: Related Content

Text Link Ads


9 Responses to “Wordpress 2.0 Permalinks, Error Codes, and Google Sitemaps”

  1. User GravatarAaron Pratt Says:

    I play around with my blog more than anyone I bet, break it, fix it, break it and I recently changed the postnames from /%category%/%postname%.html to /%category%/%postname%/ and then back again. A couple days later I noticed in sitemaps that they had indexed all the new postnames ending in / instead of .html which I changed back to again. A few errors in sitemaps for missing pages but no problems at all. Google understands blogs and how we break them now.

    Don’t forget your 301 in .htaccess and let Google straighten themselves out, they will get there, you see only spammers worry about this stuff, kidding. ;)

  2. User Gravatarseoforumz Says:

    One of my favorite WP plugins for SEO is the Ultimate Tag Warrior (UTW).

    I noticed with some versions of WP that the Permalink Structure has to have /archives/ before the /category/ in order to display the tagged sites on the ‘tag’ pages. It is a good idea to know this before you launch too many pages, as changing it changes all the post permalinks (users whop have linked to your posts using the old structure will have to find the new permalink).

    The Google sitemaps plugin is also very good.

    Thanks for posting the .htaccess code, as I am currently trying to set that up and get my 404’s working properly along with any 301 redirects for urls with ‘/’ at the end (WP creates two page urls with ‘/’ at the end and without). I also redirected my non-www. urls to the http://www. versions.

    BTW, I found this post on Search Engine Feeds syndicated news article site.

  3. User GravatarChristian Sattel Says:

    To get Wordpress send proper 404’s i found this to be working:

    put the following line into your .htaccess:
    ErrorDocument 404 /index.php?error=404

    in your template-folder, create a file 404.php, e.g.:

    Error 404 – File not Found

    a detailed article is available at the codex:
    http://codex.wordpress.org/Creating_an_Error_404_Page

  4. User GravatarAdministrator Says:

    correct but if example.com/bad/page.html doesn’t exist the htaccess file will send it into ‘the loop’ first and never hit the ‘error condition’

  5. User GravatarChristian Sattel Says:

    the line “ErrorDocument 404 /index.php?error=404″ should be above the wordpress rewrite-rules, outside of the “# BEGIN Wordpress[...]# END Wordpress” block. wordpress or some plugins may change/overwrite this part. e.g. if you edit the permalink-structure.

    for me wordpress 2 sends proper 404’s with both apache 1.3 & 2 using the instructions in my first comment (code for the 404.php was removed by the comment-system - see the codex for an example).
    wp2 seems to send 404’s even without the extra line in .htaccess, at least for me.
    i’ve checked headers with livehttpheaders & http://web-sniffer.net/

    wordpress will look if there’s a page available for the url, if not it will send a 404-header and display the 404.php of your template (if one is available). this is about wordpress 2, i don’t know how older versions behave.

    hope this helps, it worked for me wihout any problems so far.

  6. User GravatarAdministrator Says:

    Update ok because I was using the static homepage plugin it didn’t work so the correct line in htaccess should be

    ErrorDocument 404/foo/index.php?error=404

    foo = the directory you are using as a blog

    Correction Ok you need to change the structure to

    /foo/%category%/%postname%/

    the problem is if

    foo/non-existent-directory/

    gets called it will still trip up, but less likely than

    /non-existent-directory/

    getting called IMHO

  7. User GravatarMichael Gray Says:

    Additional Update

    If you upgrade to wordpress 2.0.2 this should fix it

  8. User GravatarDav Says:

    Just add in your header of your 404 page:

    http://codex.wordpress.org/Creating_an_Error_404_Page

  9. User GravatarBest WordPress Permalink, Organizational Structure for SEO and Why? Says:

    [...] GrayWolf’s SEO Blog - /%category%/%postname%/ [...]

Flyclear Discount Code