0

I have a lot of 404s on posts without /%category%/ (I have change permalink structure). I have noticed that if I put /anything/ in 404 link as category I'll end up in the right post. How can I solve it? I have around 25k 404s in google console and I need a bulk solution.

My thoughts are either to do it in htaccess or in 404.php (preferably). I was thinking to check request in 404.php and if it misses /category/ just to insert any word and make a new request toward WP to resolve the post.

Any thoughts?

2 Answers 2

3

Ok, resolved it in 404.php

<?php 

$klo_link = $_SERVER['REQUEST_URI'];  
if (preg_match("/^\/[a-zA-Z0-9\-\_]+\/$/", $klo_link)) {    
//echo "A match was found.    \n";  
//echo $klo_link;   
header("HTTP/1.1 301 Moved Permanently");   
header("Location: ".get_bloginfo('url')."/a".$klo_link);    
exit();
 }else {    
get_header();
}

Put that at the beginning of the 404.ph

0

Use Redirection plugin - https://wordpress.org/plugins/redirection/

You can set 301 redirection for all your 404 urls from WP admin itself. You can also bulk import urls from csv file.

This way you can tell google that those urls doesn't exist and permanently moved, eventually those console errors will go away.

1
  • 1
    I have more then 25k 404s. Even with bulk redirects, there should be a more elegant solution. Plus, this plugin is ok with couple of hundrets redirects, but it increases server usage with couple of thousand redirects.
    – klo
    Commented Jan 20, 2017 at 10:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.