Can Wordpress redirect to a "similar page" in case of 404 error

by cfischer   Last Updated September 26, 2017 08:08 AM

This stuff is driving me nuts. The following url does NOT exist and should return a 404:

However, if I try to access it, I get a 301 to

Even if I add a redirect to the .htaccess to redirect it somewhere else, I still get the * 301 to again.

Anybody knows what's going on?

PS this is the .htaccess:

AddHandler php5-script .php

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# END WordPress

Redirect [R=301,NC,L]

Answers 3

If you remove your Redirect from the .htaccess file, you could try adding a custom 404.php template file to your theme. I'm not sure exactly what you are asking. Do you want the page to Redirect, or do you want a custom 404 page that displays similar items?

To achieve the show similar posts using the 404.php template try this:

Create a php file named 404.php Add this to the file and save it, then upload it to your theme directory:

<?php get_header(); ?>
        <div class="container">
<div class="content">
<h2 class="entry-title">Didn't Find What You were Looking For?</h2>
<p>Perhaps one of the links below, can help.</p>
$rel_tags = get_the_tags();
foreach($rel_tags as $rel_tag)
    $rel_tagnames .= $rel_tag->name . ',';
$rel_posts = get_posts('tag=' . $rel_tagnames . '&post__not_in' . $post->ID . '&showposts=5');
if (count($rel_posts)) : ?>
    <?php foreach((array) $rel_posts as $rel_post) { ?>
        <li><a href="<?php echo $rel_post->post_name ?>"><?php echo $rel_post->post_title ?></a></li>  
    <?php } ?>
<style type="text/css">
#return-home {
<div id="return-home">
<a href="<?php bloginfo('url'); ?>" title=" <?php bloginfo('name'); ?>">Click to Go to the Home Page:&nbsp;<?php bloginfo('name'); ?></a>
<?php else : ?>

<?php endif; ?>
<?php get_sidebar(); ?>
<?php get_footer(); ?>

NOTE: You will need to replace the div's I've used with the ones your theme has or it won't look like the rest of your website. Open your index.php file and replace the <div class="container"> and <div class="content">from my file with your theme's div's.

Jeremy Jared
Jeremy Jared
August 02, 2011 23:11 PM



will create more problems than solve because that will enable other sorts of urls. and will be accessible and that is very bad for SEO since you have to pages showing the same content. I am looking for a solution to stop Wordpress from redirecting misspelled URLs and will update you I find one

Matthew Xerri
Matthew Xerri
August 31, 2011 12:20 PM

The answer is probably kind of late, but if anyone come accross the same problem then you should try the following plugin: WP 404 auto redirect to similar post.

Long story short, the plugin use the template_redirect filter and check if a 404 is about to be displayed. If so, it will explode the URL and look for a similar post / taxonomy / post type.

Hope it helps!

September 26, 2017 07:39 AM

Related Questions

PHP - redirect https to http and www to non-www

Updated November 20, 2017 18:08 PM

301 redirect not working through .htaccess

Updated March 29, 2015 06:02 AM

301 Redirect Old URL to New Wordpress Page

Updated February 28, 2017 17:08 PM