Search engine friendly URL problem
Posted: Tue Jan 06, 2004 2:21 pm
Hi,
I need to make the URL for my site more friendly to search engines. Does anyone know what the problem with this code, or server settings are, or where I can find similar code for PHP running on a w2k server?
I found a nice example in "Core PHP Programming" for putting GET variables between slashes. The example worked fine on my test server after changing the $_SERVER variables used, to ones that would work under Windows, but didn't work on the production server. After upgrading the test server to PHP ver. 4.3.4 from 4.3.1, the example file had the same problem.
The example file generates a random number that it uses as a link to the next page. This works fine and displays something like:
View Message 703
After clicking on "View Message 703" the next page a “404 page not found error”, instead of the next random number. The current code follows and this is running on:
Server: W2k
PHP: 4.3.4
I need to make the URL for my site more friendly to search engines. Does anyone know what the problem with this code, or server settings are, or where I can find similar code for PHP running on a w2k server?
I found a nice example in "Core PHP Programming" for putting GET variables between slashes. The example worked fine on my test server after changing the $_SERVER variables used, to ones that would work under Windows, but didn't work on the production server. After upgrading the test server to PHP ver. 4.3.4 from 4.3.1, the example file had the same problem.
The example file generates a random number that it uses as a link to the next page. This works fine and displays something like:
View Message 703
After clicking on "View Message 703" the next page a “404 page not found error”, instead of the next random number. The current code follows and this is running on:
Server: W2k
PHP: 4.3.4
Code: Select all
<?php
$path82 = $_SERVER['REQUEST_URI'];
echo $path82.'is<br>';
if(isset($_SERVER['REQUEST_URI']))
{
//remove .html from the end
$path = str_replace(".html", "", $_SERVER['REQUEST_URI']);
//remove leading slash
$path = substr($path, 1);
//iterate over parts
$pathVar = array();
$v = explode("/", $path);
$c = count($v);
for($i=0; $i<$c; $i += 2)
{
$pathVar[($v[$i])] = $v[$i+1];
}
print("You are viewing message " .
"{$pathVar['message']}<br>\n");
}
//pick a random ID
$nextID = rand(1, 1000);
print("<a href="{$_SERVER['PHP_SELF']}/message/$nextID.html">" .
"View Message $nextID</a><br>\n");
?>
Thanks
?>