|
php rewrite?
Ok my site is all on one page index.php, and it has ?query string (_GET) variables to navigate,
e.g. ?section=contact
e.g. ?section=about&page=services
This works fine, but now I decided I want directory structures to work as well,
e.g. /contact/
e.g. /about/services/
I can use PHP to re-write the directory names to _GET variables in the ?query string, and I can redirect the browser to the new URL with a header( "refresh: 0; url=$rewritten_url"); statement.
But then the re-written URL shows up in the browser.
I want to use header("location:$rewritten_url");, but for some reason it isn't working!
Here's the script I'm using, can anyone see why?
[code:1:21a609892e]<?php
$sOldPath = trim($_SERVER['REQUEST_URI']);
/* TODO: get rid of .html .php etc */
$aParts = preg_split("/[\/]+/", $sOldPath, -1, PREG_SPLIT_NO_EMPTY);
$sNewPath = "";
switch (count(array_slice($aParts,0,2))) {
case 2: $sNewPath = "&page=" . $aParts[1];
case 1: $sNewPath = "?section=" . $aParts[0] . $sNewPath;
}
$sNewPath = 'Location:http://' . $_SERVER['HTTP_HOST'] . '/index.php' . $sNewPath;
Header($sNewPath);
exit();
?>
[/code:1:21a609892e]
|