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/postname/, while the one for my sub-category is example/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/postname/
which does not exist will be redirected to my sub-category urlexample/stack/postname/
this pages are active and have content.
How would I go about this?
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/postname/, while the one for my sub-category is example/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/postname/
which does not exist will be redirected to my sub-category urlexample/stack/postname/
this pages are active and have content.
How would I go about this?
Share Improve this question asked Jun 5, 2019 at 19:07 XATAXATA 6712 bronze badges 5- See the answer here stackoverflow/questions/19962787/… . Example shown in that answer. – Rick Hellewell Commented Jun 5, 2019 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 Commented Jun 6, 2019 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 Commented Jun 6, 2019 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 Commented Jun 6, 2019 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/questions/268669/… – Rick Hellewell Commented Jun 6, 2019 at 20:01
1 Answer
Reset to default 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
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745429640a4627334.html
评论列表(0条)