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']));
}
[...]
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 s9yBut 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-BorisCode: 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-8Interesstingly 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.