Can WordPress redirect to a “similar page” in case of 404 error

This stuff is driving me nuts. The following url does NOT exist and should return a 404:
http://www.easyjob.net/resume/

However, if I try to access it, I get a 301 to http://www.easyjob.net/r/cover-letter/resume-and-cover-letter/

Read More

Even if I add a redirect to the .htaccess to redirect it somewhere else, I still get the * 301 to http://www.easyjob.net/r/cover-letter/resume-and-cover-letter/ 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]
</IfModule>

# END WordPress

#/RESUME/
Redirect        http://www.easyjob.net/resume/ http://www.easyjob.net/r/ [R=301,NC,L]

Related posts

Leave a Reply

4 comments

  1. 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>
    <?php  
    $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)) : ?>
        <ul>
        <?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 } ?>
        </ul>
    <style type="text/css">
    #return-home {
    display:block;
    position:relative;
    padding:5px;
    font-size:24px;
    font-weight:600;
    color:black;
    margin-top:40px;
    }
    </style>
    <div id="return-home">
    <p>
    <a href="<?php bloginfo('url'); ?>" title=" <?php bloginfo('name'); ?>">Click to Go to the Home Page:&nbsp;<?php bloginfo('name'); ?></a>
    </p>
    <?php else : ?>
    
    <?php endif; ?>
                </div>
            </div>
    <?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.

  2. I agree with @Matthew Xerri’s answer and a better solution might be to only remove the canonical redirect filter when the page that will be shown is a 404 page.

    This post explains how this can be done: http://scottnelle.com/642/prevent-wordpress-guessing-users-hit-404-error/

    function stop_404_guessing( $url ) {
        return ( is_404() ) ? false : $url;
    }
    add_filter( 'redirect_canonical', 'stop_404_guessing' );
    

    Essentially, it will only remove the filter if the page that should be shown is a 404 page.

    Alternatively you could write it a bit differently by taking bits from this issue: https://wordpress.stackexchange.com/a/227043

    function stop_404_guessing() {
        if (is_404()) {
            remove_action( 'template_redirect', 'redirect_canonical' );
        }
    }
    
    add_action( 'wp', 'stop_404_guessing' );
    
  3. Adding

    remove_filter('template_redirect','redirect_canonical');  
    

    will create more problems than solve because that will enable other sorts of urls. http://www.easyjob.net/ and http://www.easyjob.net/index.php 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

  4. 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!