Plugin Posts

12Nov/09Off

404 Errors When Integrating Zenphoto With WordPress

The Problem

In my previous post, 'A Basic WordPress And Zenphoto Integration', I noted that my Zenphoto integration had a problem with silent 404 errors. Although the pages of the gallery were being displayed nicely skinned with my WordPress theme and everything looked okay, behind the scenes they were being delivered to the browser with a HTTP status of 404, "not found". Obviously this is a very bad thing, as once I manage to get search engines indexing my site they would see the 404 and assume that the pages were not available, ignoring the fact that the content was actually there.

The Details

Some comments on the original post that I used to aid my integration suggested that this was being caused by the URL rewriting used by both WordPress and Zenphoto. Taking this lead, I did a few simple tests to narrow the location of the problem. First I disable the URL rewriting in Zenphoto. No change. Second, I disabled the URL rewriting in WordPress. Bingo; the gallery pages were now being served with a HTTP status of 200, but now my WordPress URLs were decidedly less than friendly.

Time for a bit of digging into how WordPress handles URL rewriting. Actually, not much digging was needed in this case. As the gallery is located in a sub-folder under the WordPress installation, I figured all that was needed was to make WordPress ignore this entire sub-folder when it comes to parsing rewritten URLs. This led me to 'WP_Rewrite' in the WordPress Codex. This class, defined in wp-includes/rewrite.php, handles all of the URL rewriting rules used by WordPress.