Php 重定向在Wordpress中不起作用?

Php 重定向在Wordpress中不起作用?,php,wordpress,redirect,Php,Wordpress,Redirect,我在wordpress中使用以下代码进行重定向 $currentPage = explode('?', $_SERVER ['REQUEST_URI']); $current_page_url = $currentPage[0]; if($current_page_url == '/e-commerce') { header("Location : http://www.mysite.com/complete-e-commerce-solution",true);

我在wordpress中使用以下代码进行重定向

$currentPage = explode('?', $_SERVER ['REQUEST_URI']);
  $current_page_url = $currentPage[0];
 if($current_page_url == '/e-commerce')
    {
        header("Location : http://www.mysite.com/complete-e-commerce-solution",true);
    }

我正在header.php中使用此代码,我正在重定向到第三方网站。这有问题吗?

有没有机会从
$currentPage[0]
获得
/e-commerce
“/e-commerce”
看起来更像是在
$currentPage[1]

中可以找到的东西。您需要在标题调用之后加上“exit”。但是,使用wordpress的内置功能可能会更好:

wp_redirect("Location : http://www.mysite.com/complete-e-commerce-solution");
exit;

使用wordpress函数允许插件过滤输入并清理输入(此处不适用,只是良好的实践)。

您收到的错误或结果是什么?currentPage的值是多少。但是重定向没有发生我的意思是
$current\u page\u url
的值,我的错误。因此,如果您执行
print\r($currentPage);退出你得到了什么输出?我假设这是在任何其他输出之前?为什么要使用php来实现这一点?
htaccess
还不够吗?您是使用exit还是立即退出?这是确保只发送头所必需的。