Forum Moderators: coopster

Message Too Old, No Replies

header redirect in PHP

blank page when using header redirect in error 404 pages

         

christocmp

10:15 am on Jun 27, 2005 (gmt 0)

10+ Year Member



I'm getting a strange problem when using header redirects in my error404 page.

This is the code on the 404 page;

<?php
$location = 'http://' . $_SERVER['HTTP_HOST'];
header("Location: $location");
exit();
?>

which should redirect me to the homepage. But all I'm getting is this output.

<html><body></body></html>

I'm trying to get an intelligent search system in place based on the work of David Skalar. It works sweetly locally but when live all my redirects fall over, producing the output above.

I'm using Apache 1.3 and PHP 4.2.3 (CGI mode)

any help very much appreciated.

dreamcatcher

11:36 am on Jun 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to Webmaster World christocmp. :)

Have you looked in your error logs?

anshul

12:47 pm on Jun 27, 2005 (gmt 0)

10+ Year Member



Print out bith $_SERVER['HTTP_HOST'] and $location

Try using header("Location: " . $location);.

christocmp

1:35 pm on Jun 27, 2005 (gmt 0)

10+ Year Member



Thanks for the replies. I have tried the other method and echoing the URL which all checks out fine.

I even had a chance to try the code on my own cheap webhost and it all works as expected. I've just found out we don't have access to the Apache error logs so looks like I will have to contact are hosting company and get back in to you in a bit. The PHP error logs are all clear of errors.

I have the page displaying the search dialog but its a pain feeding writing code feeding all the search data from the 404 to our search system only to be thwarted by this silly redirect issue :(