Page 1 of 1

Getting a 404 error but page is displayed correctly

Posted: Sun Oct 26, 2008 12:01 pm
by Caspian
Hi

I've been using Serendipity for a while now and am happy with it. I've just finished this site, which seems to work fine, but when I use Firebug to monitor the network responses, I see that the page request generates a 404 error for every page in the site. This isn't visible to the end user, and the page is displayed correctly. Does anyone have an idea why this might be? I did a similar site a while ago and didn't get this problem.

Background info:

Using static pages for the main navigation items
Using mod rewrite for pretty URLs
.htaccess looks like this:

Code: Select all

# BEGIN s9y
ErrorDocument 404 /index.php
DirectoryIndex /index.php

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^kingstonbeekeepers\.org\.uk [NC]
RewriteRule ^(.*)$ http://www.kingstonbeekeepers.org.uk/$1 [R=301,L]
RewriteRule ^((archives/([0-9]+)-[0-9a-z\.\_!;,\+\-\%]+)/?) /index.php?/$1 [NC,L,QSA]
RewriteRule ^(authors/([0-9]+)-[0-9a-z\.\_!;,\+\-\%]+) /index.php?/$1 [NC,L,QSA]
RewriteRule ^(feeds/categories/([0-9;]+)-[0-9a-z\.\_!;,\+\-\%]+\.rss) /index.php?/$1 [NC,L,QSA]
RewriteRule ^(feeds/authors/([0-9]+)-[0-9a-z\.\_!;,\+\-\%]+\.rss) /index.php?/$1 [NC,L,QSA]
RewriteRule ^(categories/([0-9;]+)-[0-9a-z\.\_!;,\+\-\%]+) /index.php?/$1 [NC,L,QSA]
RewriteRule ^archives([/A-Za-z0-9]+)\.html /index.php?url=/archives/$1.html [NC,L,QSA]
RewriteRule ^([0-9]+)[_\-][0-9a-z_\-]*\.html /index.php?url=$1-article.html [L,NC,QSA]
RewriteRule ^feeds/(.*) /index.php?url=/feeds/$1 [L,QSA]
RewriteRule ^unsubscribe/(.*)/([0-9]+) /index.php?url=/unsubscribe/$1/$2 [L,QSA]
RewriteRule ^approve/(.*)/(.*)/([0-9]+) /index.php?url=approve/$1/$2/$3 [L,QSA]
RewriteRule ^delete/(.*)/(.*)/([0-9]+) /index.php?url=delete/$1/$2/$3 [L,QSA]
RewriteRule ^(admin|entries)(/.+)? /index.php?url=admin/ [L,QSA]
RewriteRule ^archive/? /index.php?url=/archive [L,QSA]
RewriteRule ^(index|atom[0-9]*|rss|b2rss|b2rdf).(rss|rdf|rss2|xml) /rss.php?file=$1&ext=$2
RewriteRule ^(plugin|plugin)/(.*) /index.php?url=$1/$2 [L,QSA]
RewriteRule ^search/(.*) /index.php?url=/search/$1 [L,QSA]
RewriteRule ^comments/(.*) /index.php?url=/comments/$1 [L,QSA]
RewriteRule ^(serendipity\.css|serendipity_admin\.css) /index.php?url=/$1 [L,QSA]
RewriteRule ^index\.(html?|php.+) /index.php?url=index.html [L,QSA]
RewriteRule ^htmlarea/(.*) /htmlarea/$1 [L,QSA]
RewriteRule (.*\.html?) /index.php?url=/$1 [L,QSA]
RewriteRule ^simon/(.*) /index.php?url=/apiaries/$1 [L,QSA]

<Files *.tpl.php>
    deny from all
</Files>

<Files *.tpl>
    deny from all
</Files>

<Files *.sql>
    deny from all
</Files>

<Files *.inc.php>
    deny from all
</Files>

<Files *.db>
    deny from all
</Files>

# END s9y

Re: Getting a 404 error but page is displayed correctly

Posted: Sun Oct 26, 2008 1:02 pm
by garvinhicking
Hi!

The 404 actually means that mod_rewrite seems to be not working on your page.

A 404 only occurs when the Apache ErrorDocument fallback is used. In this case, when PHP runs as a CGI the PHP header 200 OK is not properly emitted.

This has been fixed in the s9y 1.4 release tree, there a second PHP header is emitted to work properly in CGI environments.

You now have those options:

1. Try to remove the "ErrorDocument 404..." in your .htaccess - then your custom URLs should no longer be worked. then you can check why mod_rewrite is not working, and maybe enable this properly?

2. Upgrade to s9y 1.4, or manually backport those patches:
http://svn.berlios.de/viewcvs/serendipi ... 6&view=rev

HTH,
Garvin

Re: Getting a 404 error but page is displayed correctly

Posted: Sun Oct 26, 2008 3:31 pm
by Caspian
Hi Garvin

Thanks for the quick response. I've manually ported all the patches you listed but I'm still getting the 404. I wanted to avoid removing the ErrorDocument in the live environment because I've only just launched the site and our users will be more likely to view it today.

Is there anything else I might be missing apart from those patches? The version I'm running is 1.3.1.

Thanks
Simon

Re: Getting a 404 error but page is displayed correctly

Posted: Sun Oct 26, 2008 4:08 pm
by garvinhicking
Hi!

Hm, this patch does not include all places. I did not have the time to check that.

you might need to search all your PHP files for "header('HTTP" and make sure, they all got a second line like "header('Status: 200 OK')".

In index.php you need to search for:

Code: Select all

header('HTTP/1.0 200');
(quite near the top of the file)

and add this after it:

Code: Select all

header('Status: 200 OK');
Getting mod_rewrite to work properly would be a good option though, it performs a bit faster and leaves no redundant error-log entries for missing 404 files.

Regards,
Garvin

Posted: Sun Oct 26, 2008 7:09 pm
by Caspian
That did it! Thanks for your help Garvin. I'll try to find out why the mod_rewrite isn't working properly.

Simon