Forum Moderators: coopster

Message Too Old, No Replies

Error in URL stripping and redirecting

... please help?

         

internetheaven

6:46 pm on Dec 21, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Having some trouble with a set of scripts I'm trying to consolidate, the strings coming to the /folder/go.php are:

/folder/go.php?name1
/folder/go.php?name2
/folder/go.php?name3
Etc.

<?php
$referred = $_SERVER['QUERY_STRING'];
$forward = str_replace("http://www.example.com/go.php?", "", $referred);
if($forward == "name1")
{
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://www.example.com/folder/file1.php" );
}
elseif($forward == "name2")
{
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://www.example.com/folder/file2.php" );
}
elseif($forward == "name3")
{
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://www.example.com/folder/file3.php" );
}
else
{
Echo "sorry that page does not exist anymore";
}
?>

There is no other scripting on the page and when I use echo $forward; it shows the right words on the page but yet when I follow the links to /folder/go.php?name2 it just shows a blank page (just html template coding).

Anyone see what I've done wrong?

Thanks
Mike

PHP_Chimp

9:17 pm on Dec 21, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



/folder/go.php?name1
/folder/go.php?name2
/folder/go.php?name3
Etc.

<?php
$referred = $_SERVER['QUERY_STRING'];
$forward = str_replace("http://www.example.com/go.php?", "", $referred);
if($forward == "name1")

Assuming url = /folder/go.php?name1

$referred = 'name1'; // everything after the?
$forward = ... does nothing as there is no example.com/

void header ( string $string [, bool $replace [, int $http_response_code ]] )

For your headers have you tried -
header('Location: ...', true /* or false depending on you */, 301);
As this will send both the 301 status and the new location.