Angepasste 404 Site
Noch hab ich meine Migrationsstrategie von Serendipity auf Wordpress noch nicht niedergeschrieben. Doch bin ich der perfekten Lösung wieder einen Schritt näher gekommen. Der eine oder andere wird vielleicht mitbekommen haben das manche Posts nicht betrachtet werden können. Man erhält einen 404 Error da der Post Slug nicht stimmt. Das Problem entstand bei der Migration – da Serendipity hier anders vorgeht als Wordpress. Da ich nicht alle meine Posts per Hand durchgehen will hab ich die 404 Seite etwas intelligenter gestaltet.
Von nun an, wenn jemand auf den Titel eines Posts klickt und den 404 Error bekommt werde ich automatisch per eMail informiert und werde diesen Fehler auch sofort ausbessern. Hoffe so auf kurz oder lang alle falschen Post Slugs beseitigen zu können.
Für die Erstellung dieser Seit waren codex.wordpress.org, binarymoon.co.uk und alistapart.com sehr hilfreich.
Der Code meiner 404 Error Page:
[code lang="php"]< ?php header("HTTP/1.1 404 Not Found"); ?>
< ?php get_header(); ?>
< ?php _e('Fehler 404 - Nicht gefunden'); ?>
You
< ?php
#some variables for the script to use
#if you have some reason to change these, do. but wordpress can handle it
$adminemail = get_bloginfo('admin_email'); #the administrator email address, according to wordpress
$website = get_bloginfo('url'); #gets your blog's url from wordpress
$websitename = get_bloginfo('name'); #sets the blog's name, according to wordpress
if (!isset($_SERVER['HTTP_REFERER'])) {
#politely blames the user for all the problems they caused
echo "tried going to "; #starts assembling an output paragraph
$casemessage = "All is not lost!";
} elseif (isset($_SERVER['HTTP_REFERER'])) {
#this will help the user find what they want, and email me of a bad link
echo "clicked a link to
"; #now the message says You clicked a link to...
#setup a message to be sent to me
$failuremess = "A user tried to go to $website"
.$_SERVER['REQUEST_URI']." and received a 404 (page not found) error. ";
$failuremess .= "It wasn't their fault, so try fixing it.
They came from ".$_SERVER['HTTP_REFERER'];
mail($adminemail, "Bad Link To ".$_SERVER['REQUEST_URI'],
$failuremess, "From: $websitename
$casemessage = "An administrator has been emailed
about this problem, too.";#set a friendly message
}
echo " ".$website.$_SERVER['REQUEST_URI']; ?>
and it doesn't exist.
< ?php echo $casemessage; ?> You can click back and try again or search for what you're looking for.
Recent Posts
-
< ?php
- < ?php the_title(); ?>
query_posts('posts_per_page=5');
if (have_posts()) : while (have_posts()) : the_post(); ?>
< ?php endwhile; endif; ?>
< ?php get_sidebar(); ?>
< ?php get_footer(); ?>
[/code]
Sollte an dem Code etwas nicht ganz stimmen, würde ich mich über ein Kommentar freuen.
























