重定向在 Wordpress 中不起作用?

重定向在 Wordpress 中不起作用?

问题描述:

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

I am using below code for redirection in 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 中使用此代码,我正在重定向到第三方站点.这是问题吗?

I am using this code in header.php, i am redirecting to third party site.is that problem?

您需要在标头调用之后使用exit".但是,您可能会更好地使用 wordpress 的内置 wp_redirect 函数:

you need to follow the header call with an 'exit`. However, you might be better using wordpress's inbuilt wp_redirect function:

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

使用 wordpress 函数允许插件过滤输入并清理输入(这里不太适用,只是很好的做法).

Using wordpress functions allows plugins to filter the input and sanitises the input (not so applicable here, just good practice).