【问题标题】:Redirection not working in Wordpress?重定向在 Wordpress 中不起作用?
【发布时间】:2011-09-08 08:38:24
【问题描述】:

我在 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的值是多少
  • @Ross 我仅将 $currentPage 的值设为 /e-commerce。但重定向没有发生
  • 我的意思是$current_page_url的值,我的错。因此,如果您执行print_r($currentPage); exit;,您会得到什么输出?我假设这是在任何其他输出之前?
  • 你为什么要使用 php 呢? htaccess 不够吗?

标签: php wordpress redirect


【解决方案1】:

有没有机会从$currentPage[0] 得到/e-commerce'/e-commerce' 看起来更像是在 $currentPage[1] 上找到的东西。

【讨论】:

    【解决方案2】:

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

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

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

    【讨论】:

    • 你是使用exit还是之后立即死亡?这是确保只发送标头所必需的。
    猜你喜欢
    • 2017-08-13
    • 1970-01-01
    • 2017-12-08
    • 1970-01-01
    • 1970-01-01
    • 2021-01-17
    • 2018-01-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多