admin管理员组文章数量:1414878
I've got a WordPress site that includes pages pulled from a different database. The problem is that these other pages return a 404 status code. (The WordPress posts/pages are fine.)
The 404'ed pages display fine, and I removed the "Page not Found" text from the title tag in WordPress. But Googlebot and W3C see the 404 header.
So: wow does one tell Apache to suppress a 404 status? And will Apache override WordPress's 404 header?
Does that make sense? What other info and things should I be looking at?
Can I suppress the status code in .htaccess so I don't change WP core files?
I've got a WordPress site that includes pages pulled from a different database. The problem is that these other pages return a 404 status code. (The WordPress posts/pages are fine.)
The 404'ed pages display fine, and I removed the "Page not Found" text from the title tag in WordPress. But Googlebot and W3C see the 404 header.
So: wow does one tell Apache to suppress a 404 status? And will Apache override WordPress's 404 header?
Does that make sense? What other info and things should I be looking at?
Can I suppress the status code in .htaccess so I don't change WP core files?
Share Improve this question edited Oct 19, 2018 at 3:05 Gonçalo Peres 1171 gold badge1 silver badge11 bronze badges asked Jun 14, 2010 at 16:20 markratledgemarkratledge 8,7356 gold badges40 silver badges62 bronze badges4 Answers
Reset to default 12You can either add custom rewrites to your pages. Or on the top of the template files that wrap your other pages just output header('HTTP/1.1 200 OK');
.
WordPress offers the function status_header()
to return the correct status-code.
You can call this function inside your WordPress template/function:
// Will return http status header "200 OK"
status_header(200);
Wordpress is PHP, so look for where it's sending something like:
header("HTTP/1.0 404 Not Found");
Take a look at the pre_handle_404 hook (added in v4.5.0): https://developer.wordpress/reference/hooks/pre_handle_404/
// add to your functions.php
add_filter('pre_handle_404', function($preempt, $wp_query) {
global $wp;
$customPages = ['custom-1','custom-2','custom-3'];
if (in_array($wp->request, $customPages)) {
$preempt = true;
}
return $preempt;
}, 10, 2);
本文标签: headersHow does one suppress a 404 status code in a WordPress page
版权声明:本文标题:headers - How does one suppress a 404 status code in a WordPress page? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745225573a2648592.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论