Can anyone tell me how to redirect a 404 page to another specific page on my wordpress blog? Here's what the php snippet looks like: <?php else : ?> <h2 class="center">Not Found</h2> <?php endif; ?> <?php get_sidebar(); ?> <?php get_footer(); ?> Thanks in advance
Yea, put this in the <head> section of the 404 page. <META HTTP-EQUIV="refresh" content="1; URL=http: //www .domainname.us/"> Where the 1 is the seconds before the page will redirect to that url in the code.. You can put a N in for the 1 if you want no delay. Make sure to put in the URL of the page you want the redirect to go to and remove the spaces. Enjoy, Boulder
I need help with that also, but, there is no <head> section of my 404.php. Where exactly do I put this code to redirect ? <?php/*Template Name: Error 404 Template*/?> <?php get_header(); ?><div id="content"><?php include(TEMPLATEPATH."/l_sidebar.php");?><div id="contentmiddle"><div class="contenttitle"> <h1>Sorry, Not Found, Error 404</h1><br /> <p>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 <noreply@$website>"); #email you about problem $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: <?php include(TEMPLATEPATH . "/searchform.php"); ?> orgo to the <li><a href="<?php echo get_settings('siteurl'); ?>" title="Go to the blog homepage">homepage</a></li> or read the last <li><?php echo $getOptions["num_posts"]; ?> blogs →</li><h2>Last <?php print(isset($getOptions["num_posts"])?$getOptions["num_posts"]:"8"); ?> blog posts</h2> <ol> <?php get_archives('postbypost', isset($getOptions["num_posts"])?$getOptions["num_posts"]:8, '<li>', '</li>'); ?> </ol> <ol> <?php wp_list_cats('sort_column=name&optioncount=1&hierarchical=0&feed=RSS'); ?> </ol></p> </div><?php include(TEMPLATEPATH."/r_sidebar.php");?></div><?php get_footer(); ?>
Oh okay, well in that case, there are two things we can try. Option 1) Make a head section and place the refresh code in the tag. Like this: <head>put the refresh code here</head> Option 2) Put this code in your .htaccess file with link to the destination page! Redirect /404.php http:// www. mydomainname.com/gohere.php Try that and see how it works! Of course, on a blog the path to the 404.php and other file page might look more like this: Redirect /wp-content/themes/themename/404.php http:// www. mydomainname.com/wp-content/themes/themename/gohere.php Boulder
Umm...I've got a kind of stupid question. I don't have a 404.php in the theme that I'm currently using. Which file would I edit if I don't have 404.php?
Yea.. If I remember correctly? By using the .htaccess method, the user will not even know the redirect exists.. Using the refresh method the 404 page will be shown for a second than it will redirect.. Both could have their own unique advantages in certain circumstances. Thanks for the rep.. j.blu. Have fun! Boulder
Okay here is code structure for a basic WP 404 file.. Just make a 404.php file and put this code in there.. look at your main index.php or home.php and match up the first three lines of code with that file on this file. Like use the same div id=" " And change the sidebar paths to your side bar file name or names, depending on if you have one or two sidebars.. Remove one of the includes if only one sidebar! You could also use something like what hmansfield has above and edit it to match your theme. <?php get_header(); ?> <div id="content"> <div id="contentleft"> <h1>Not Found, Error 404</h1> <p>The page you are looking for no longer exists.</p> </div> <?php include(TEMPLATEPATH."/l_sidebar.php");?> <?php include(TEMPLATEPATH."/r_sidebar.php");?> </div> <!-- The main column ends --> <?php get_footer(); ?> Boulder
Thanks as well...rep given. <edit> Just wanted to add that I put in the code the way that you told me to, and for the first time in days, I didn't get any "bad Link" errors...I was getting hundreds a day. That seemed to do the trick, thanks again for the help.
could always use this plugin > http://urbangiraffe.com/plugins/redirection/ it monitors/logs 404 errors then u just decide where you want it redirected too!