1

I have a b blog of over 200k+ post and I moved all post from a specific category to a subcategory, I have also deleted the post from the my main site, so all the post of that category have been moved to a subcategory.

Our analytics show that a lot of crawling errors, and my wp permalink structure for main site is example.com/postname/, while the one for my sub-category is example.com/stack/postname/

The solution I came up with is to redirect all visits for non-existant URLs of main site to subcategory URLs

Example:

  • mysite.com/postname/ which does not exist will be redirected to my sub-category url
  • example.com/stack/postname/ this pages are active and have content.

How would I go about this?

  • See the answer here stackoverflow.com/questions/19962787/… . Example shown in that answer. – Rick Hellewell Jun 5 at 19:28
  • That does not fix my issue, because I don't have 404 error page at my public_html, wp theme function would be the best recommendation. – XATA Jun 6 at 14:01
  • If you use that link, you can see how to redirect a '404' response to another page. You provide the page you want to show in the command. You don't need a 404 page, you just need the 'errordocument' command to 'catch' a 404 response and send it to the page/link you desire. – Rick Hellewell Jun 6 at 18:08
  • its not working.check my post, I did not mention specific url, I mention urls that match the same url i deleted – XATA Jun 6 at 19:41
  • errordocument 404 /your-subcatetory-page-without-domain-name . Place the lines above the WP htaccess lines. Use the actual page you want to redirect to if a page is not found. If you want to do some WP logic to a specific page based on some condition, then create/use a '404' template. Also, see wordpress.stackexchange.com/questions/268669/… – Rick Hellewell Jun 6 at 20:01
1
<?php

header("HTTP/1.1 301 Moved Permanently");

header("Location: https://{$_SERVER['SERVER_NAME']}/subcategory{$_SERVER['REQUEST_URI']}"); 

exit();

?>

The above code was added directly to themes 404.php and everything worked as expected

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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