Forum Moderators: coopster
and notfound.php as
<?php
$request = $_SERVER['$REQUEST_URI'];
$location = strtolower($request);
$newlocation = strtr($location, "_", "-");
if ($newlocation==$request) {
header('Location: [mysite.com...]
} else {
$newlocation = "http://www.mysite.com" + $newlocation;
header('Location: $newlocation');
}
?>
BUT it's not working.. REQUEST_URI is apparently blank.. (I stuck a file write in there to find out what was happening)
Is it recommended to use PHP for 404 correction's and, if so, can you suggest what might be wrong?
Thanks
echo $request; doesn't do anything for me.. I did think of that but couldn't see what it did (I'd expected output to screen)
so instead opted for
$file="test.txt";
$fp = fopen($file,"a");
fwrite($fp, "\r\n=?");
fwrite($fp, $request);
fwrite($fp, "\r\n=>");
fwrite($fp, $newlocation);
fclose($fp);
which I take to be foolproof.. and it does indeed output what I'd expect.. so does the filter.. it's just that the input seems to be blank.
This originally from a suggestion by ggrot in thread [webmasterworld.com...] to use PHP_SELF but that generates only /notfound.php i.e. the location of the php file itself not the requested URI.
There's no conflicting Redirects in the htaccess as I removed them all.. this is all inside a temp directory while I'm trying it.
I wondered if this might be because it's two steps.. one through .htaccess
Do we know, has anyone else used PHP for 404 correction that I could see example?
<?php
$request = $_SERVER['REQUEST_URI'];
$newrequest = strtolower($request);
$newrequest = strtr($newrequest, "_", "-");
if ($newrequest==$request) {
header('Location: [mysite.com...]
} else {
$newrequest = "Location: [mysite.com".$newrequest;...]
header($newrequest);
}
?>
and now it works and I am happy :)