Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将wordpress 404第200页的状态代码更改为404_Php_Wordpress - Fatal编程技术网

Php 将wordpress 404第200页的状态代码更改为404

Php 将wordpress 404第200页的状态代码更改为404,php,wordpress,Php,Wordpress,我想将wordpress默认4040页面状态代码(200 OK)更改为404。 我已经尝试过这样做,但它仍然返回404页,200 Ok状态 add_action('template_redirect', '_custom_redirect'); function _custom_redirect() { global $wp_query; $wp_query->set_404(); status_header(404); in

我想将wordpress默认4040页面状态代码(200 OK)更改为404。 我已经尝试过这样做,但它仍然返回404页,200 Ok状态

add_action('template_redirect', '_custom_redirect');
function _custom_redirect() {
        global $wp_query;
        $wp_query->set_404();
        status_header(404);
        include( get_query_template( '404' ) );
        exit;
}

我需要这样做只是为了谷歌。有很多旧的网址,谷歌仍然索引,但没有存在和返回404未找到。我想如果我返回404状态,它将停止索引(根据此)

我怀疑将200页状态设置为404页是WordPress的默认行为,但我猜在404.php上添加标题应该可以做到这一点

<?php header("HTTP/1.0 404 Not Found"); ?>

因为我目前使用以下方法重定向我的404:

<?php header("Location: ../"); ?>

这可能是一个解决办法。 用它

我添加了
状态_头(404)在我的控制器中。