Dear DP Members, PHP 301 permanent redirect is not working on my site pages. The code I am using is Header( "HTTP/1.1 301 Moved Permanently" ); Header( "Location: http://www.personal-trainers.com/find_personal_trainer.php" ); Could you guys help me to solve this issue. Thanks in advance
Try a lower case H. header( "HTTP/1.1 301 Moved Permanently" ); header( "Location: http://www.personal-trainers.com/find_personal_trainer.php" ); PHP: Also, are you getting any error?
Thanks for the suggestion, I tried the lower case but the result is the same again. The code was there in the pages and was working fine till recent past. I am not getting any errors. I am getting the old page which I do not want to show.
Make absolutely sure there is no white space or linebreak before any php tag on the page. Also set error_reporting to All: error_reporting(E_ALL); header( "HTTP/1.1 301 Moved Permanently" ); header( "Location: http://www.personal-trainers.com/find_personal_trainer.php" ); PHP:
There is absolutely no white space or breaks before the php tags. The code is at the very beginning of the page.
I just tried the code you originally posted. If it was working before ask your host what they changed. I would try putting the redirect at the very bottom of the page. If your host has output buffering turned off and you send the headers and than try to print something you'll get an error. The other thing you could try is to just put this code in the page, and than add stuff in slowly to identify where the problem lies. The only reason I can see this not working is printing something after sending the headers... but it could be something else.
Thanks Andrew.. let me check with the hosting providers. The site was moved to a new server recently. This could well be the reason. Something might have got disturbed during the server. Thanks for the advice.
Hi! I think you can use JavaScript redirect method in php. The code below works fine- <?php $redirectURL ="index.php"; print "<script>"; print "self.location='".$redirectURL."';"; print "</script>"; ?>