Page 1 of 1

404s in error.log after changing Permalink-Structure

Posted: Sat Dec 31, 2005 1:28 pm
by Boris
I think this is no real s9y-issue, but perhaps anyone knows a good solution.

A few days ago I switched my permalinkstructure (e.g. from /categories to /kategorien) and use a redirect.php, which I include at index.php, to redirect from the old URL to the new:

Code: Select all

function s9y_boris_redirect($to) {
        header($_SERVER["SERVER_PROTOCOL"].' 301 Moved Permanently');
        header('Location: http://example.com'.$to);
        ?>
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html>
<head><title>301 Moved Permanently</title></head>
<body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="<?php echo $to; ?>">here</a>.</p>
<hr>
<address><?php echo "{$_SERVER['SERVER_SOFTWARE']} Server at {$_SERVER['SERVER_NAME']} Port {$_SERVER['SERVER_PORT']}"; ?></address>
</body>
</html>
<?php
        exit;
}

if(preg_match('#/categories/#', $_SERVER['REQUEST_URI'])) {
        s9y_boris_redirect(preg_replace('#/categories/#', '/kategorien/', $_SERVER['REQUEST_URI']));
}
[...]
This setup works quite good in the browsers, it redirects everythings as I should. Then I changed my .htaccess in the way the s9y-admin said after changing the Permalinks.

Code: Select all

# BEGIN s9y
ErrorDocument 404 /index.php
DirectoryIndex /index.php
php_value session.use_trans_sid 0
php_value register_globals off

RewriteEngine On
RewriteBase /
RewriteRule ^(artikel/([0-9]+)-[0-9a-z\.\_!;,\+\-]+\.html) index.php?/$1 [L,QSA]
RewriteRule ^(autoren/([0-9]+)-[0-9a-z\.\_!;,\+\-]+) index.php?/$1 [L,QSA]
RewriteRule ^(feeds/kategorien/([0-9;]+)-[0-9a-z\.\_!;,\+\-]+\.rss) index.php?/$1 [L,QSA]
RewriteRule ^(feeds/autoren/([0-9;]+)-[0-9a-z\.\_!;,\+\-]+\.rss) index.php?/$1 [L,QSA]
RewriteRule ^(kategorien/([0-9;]+)-[0-9a-z\.\_!;,\+\-]+) index.php?/$1 [L,QSA]
RewriteRule ^artikel([/A-Za-z0-9]+)\.html index.php?url=/artikel/$1.html [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 ^archiv/? index.php?url=/archiv [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 ^suche/(.*) index.php?url=/suche/$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 (.*\.html?) index.php?url=/$1 [L,QSA]

# END s9y
This works well to. All the new-style URL work perfectly.


But today I noticed in my error.log, that all those new style-URLs produce 404-Errors in my Logs

Code: Select all

[Sat Dec 31 08:23:44 2005] [error] [client xx.xx.xx.xx] File does not exist: /.../categories/5-XXXX
[Sat Dec 31 08:23:45 2005] [error] [client xx.xx.xx.xx] File does not exist: /.../authors/2-Boris
[Sat Dec 31 08:23:50 2005] [error] [client xx.xx.xx.xx] File does not exist: /.../kategorien/5-XXXX
[Sat Dec 31 08:23:52 2005] [error] [client xx.xx.xx.xx] File does not exist: /.../autoren/2-Boris
This never happened with the old setup, but strangly the Server-Responds are OK:

Code: Select all

GET /categories/5-XXXX HTTP/1.0

HTTP/1.1 301 Moved Permanently
Date: Sat, 31 Dec 2005 09:17:45 GMT
Server: Apache/1.3.31 (Unix) FrontPage/5.0.2.2635 PHP/4.4.0
Vary: Host
X-Powered-By: PHP/4.4.0
Location: http://example.com/kategorien/5-XXXX
Transfer-Encoding: chunked
Content-Type: text/html
[...]

Code: Select all

GET /kategorien/5-XXXX HTTP/1.0

HTTP/1.1 200 OK
Date: Sat, 31 Dec 2005 09:18:17 GMT
Server: Apache/1.3.31 (Unix) FrontPage/5.0.2.2635 PHP/4.4.0
Vary: Host
X-Powered-By: PHP/4.4.0
X-Blog: Serendipity
Set-Cookie: PHPSESSID=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
X-Serendipity-InterfaceLang: de
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8
So there should be no reason for a 404 in the Server-Log, but exactly these to GETs produced 404s too. I know this failure is more optical but an error-log full of "file not found" is quite anoying and could "hide" real errors.
Interesstingly the access.log shows the right response-code (301 and 200).

Does anyone have a solution for this, if not it is not too bad for me and I'll life with this weird behavior. :)

Re: 404s in error.log after changing Permalink-Structure

Posted: Sat Dec 31, 2005 4:33 pm
by garvinhicking
I understand this behaviour might drive you nuts. :-)

The reason for this, is that no .htacces rewriteRule matches your /categories/ request.

Now, what your webserver does is that when no mod_rewrite pattern matches, is that it would like to emit a 404 error.

But in your .htaccess file you have a "ErrorDocument 404 index.php" directive. This now passes the request through to your index.php, where your preg-match will emit a right header.

HOWEVEr, the entry in your error log has already been made at the point where your webvserver exexutdes the ErrorDocument.

Now for the solution: You'll need a rewrite rule inside your .htaccess file that catches /categories/ URLs and just redirects plainly to "index.php". Then no 404 error is made anymore.

Best regards,
Garvin

Re: 404s in error.log after changing Permalink-Structure

Posted: Sat Dec 31, 2005 6:02 pm
by Boris
Thank you Garvin. I understand your explanation regarding /categories, but the new-style permalinks like /kategorien actually ARE in .htaccess and create 404s.

I added those entries to .htaccess:

Code: Select all

RewriteRule ^categories index.php [L,QSA]
RewriteRule ^authors index.php [L,QSA]
This prevents the 404s for these URLs. But the 404s for /kategorien stay.

Code: Select all

[Sat Dec 31 17:48:30 2005] [error] [client xx.xx.xx.xx] File does not exist: /.../kategorien/3-Allgemeines
So, this line causes an 404 regardless whats in place of "kategorien":

Code: Select all

RewriteRule ^(kategorien/([0-9;]+)-[0-9a-z\.\_!;,\+\-]+) index.php?/$1 [L,QSA]

P.S. in German: Ich wünsche schon mal nen Guten Rutsch :)

Posted: Sat Dec 31, 2005 6:08 pm
by Boris
D'oh. I catched the error. :oops:

It was the Bug fixed in 0.9.1, to which I never upgraded. I didn't notice this before because I always used my old .htaccess of 0.8 (or 0.7?) and triggered the error when updating the .htaccess with the output of s9y 0.9.

Thank very much you for your Help Garvin.


New Year's pledge 2006: Upgrade to every Bugfixrelease and suscribe to Amazon to buy Garvin something from his list for all his s9y-effords. :)

Posted: Sun Jan 01, 2006 3:57 pm
by garvinhicking
Hehe, I wouldn't mind your conclusion! ;)

But good you solved the error, happy that it works now. :-)

Have a good 2006,
Garvin