WordPress.org

Forums

301 redirect and 404 errors (1 post)

  1. guantanamera
    Member
    Posted 1 year ago #

    Have migrated to WP but have massive amounts of 404 errors (34,000 to be exact).
    Google Webmaster indicates the errors but when clicked they redirect correctly
    Have redirected using following code. Any obvious mistakes ?:
    in htaccess:

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(es|en|de)/.+-([0-9]+)\.html$ ?antiguoID=$2&antiguoLANG=$1 [L]

    en php (/wp-content/themes/citygonow/header.php):

    if(isset($_GET['antiguoID']) && isset($_GET['antiguoLANG'])){
        $antID=$_GET['antiguoID'];
        $antLANG=$_GET['antiguoLANG'];
    
        $match=$wpdb->get_results('select det.post_id from cgn_detalles det where oldid='.$antID);
        if($match){
            $newID=$match[0]->post_id;
            if($antLANG!='es'){
                $newID=icl_object_id($newID, get_post_type($newID, false, $antLANG));
            }
            $npguid=get_permalink($newID);
            header("Location: ".$npguid, true, 301);
            exit;
        }else{
            header("HTTP/1.0 410 Gone");
            header("Status: 410");
            echo "removed content";
            exit;
        }
    }

    [Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum's parser.]

Topic Closed

This topic has been closed to new replies.

About this Topic