This question already has an answer here:
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();
}
?>
I am getting the error : Cannot modify header information - headers already sent by
.
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 actually header("Location: url of another site"); will not support in wordpress. Instead of this you can use
and for home page just use
<?php wp_redirect( home_url() ); exit; ?>
this will solve your problem of redirection.Try hooking your function to INIT HOOK
try using javascript instead
check the reference here
Header Information already sent is a wordpress's common error, like as you mentioned you want to redirect the web site then you have to options to follow.
Create a wordpress Template file do not call header in that file
<?php /* Template Name:Redirect*/ ?> <?php //get_header();?> <!-- Do not un comment this function -->Write your code here Write your code here Write your code here Write your code here <?php get_footer();?>
Or you can redirect with java script's window.location function
<script>document.write(location.http://google.com); </script>