在 PHP 中重定向到页面 [英] Redircting to a page in PHP
问题描述
我正在尝试根据其引用者重定向到页面.布局就像
I am trying to make a redirect to page based on its referrer. the layout is like
<?php
$URL_REF = $_SERVER['HTTP_REFERER'];
if($URL_REF == "url of my site") {
header("Location: url of another site");
exit();
}
else {
header("Location: my home page");
exit();
}
?>
我收到错误:无法修改标头信息 - 标头已由
发送.
我必须将我的 php.ini 修改为 output_buffering = On 但我不能这样做,因为我在 hostgator 中有一个共享主机帐户.谁能建议我现在有哪些选择?我可以通过更改代码来实现吗?如果是,那么有哪些变化?
I have to modify my php.ini to output_buffering = On but I can't do this as I have a shared hosting account in hostgator. can anyone suggest me what options now I have? can I do it by changing my code? If yes, than what changes?
推荐答案
Hi 实际上 header("Location: url of another site");将不支持 wordpress.你可以使用
Hi actually header("Location: url of another site"); will not support in wordpress. Instead of this you can use
<?php wp_redirect( 'http://www.example.com', 301 ); exit; ?>
对于主页只需使用 <?php wp_redirect( home_url() );出口;?>
这将解决您的重定向问题.
and for home page just use <?php wp_redirect( home_url() ); exit; ?>
this will solve your problem of redirection.
这篇关于在 PHP 中重定向到页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!