admin管理员组文章数量:1425801
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
本文标签: functionsHow do I redirect all 404 error url to Subcategory url
版权声明:本文标题:functions - How do I redirect all 404 error url to Subcategory url 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745429640a2658269.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论