Thread: php rewrite?
View Single Post
Old 03-22-2004, 07:51 PM   #1 (permalink)
LazyJim
Moderator
 
LazyJim's Avatar
 
Join Date: 10-13-03
Location: UK
Posts: 2,819
iTrader: 0 / 0%
Latest Blog:
None

LazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to all
Send a message via MSN to LazyJim
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]
__________________

-LJ-

My advice is to look at each case individually, with an informed mind and an appropriately balanced and objective viewpoint.

Web Design and Development, Ipswich, UK.
My deviantArt
LazyJim is offline   Reply With Quote
Sponsored Links
SEO Hosting by HostGator  Advertise Here  Buy Blog Links