| Coding Forum Problems with your code? Let's hear about it. |
03-22-2004, 07:51 PM
|
#1 (permalink)
|
|
Moderator
Join Date: 10-13-03
Location: UK
Posts: 2,819
Latest Blog: None
|
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]
|
|
|
03-22-2004, 07:58 PM
|
#2 (permalink)
|
|
Moderator
Join Date: 10-13-03
Location: UK
Posts: 2,819
Latest Blog: None
|
Oh yeah, and this script run with .htaccess ErrorDocument 404 directive.
Or does Location: redirect change the visible address too??
|
|
|
03-22-2004, 07:59 PM
|
#3 (permalink)
|
|
Moderator
Join Date: 10-13-03
Location: UK
Posts: 2,819
Latest Blog: None
|
i suppose I could make index.php my ErrorDocument, but the redirect not working really bugs me!
|
|
|
03-22-2004, 08:12 PM
|
#4 (permalink)
|
|
Moderator
Join Date: 10-13-03
Location: UK
Posts: 2,819
Latest Blog: None
|
Well I fixec my index.php to convert the directory based nav to the ?query based one it was already using, and changed my 404 ErrorDocument to index.php.
It works: http://www.alpha-matrix-design.co.uk/about/services/
|
|
|
03-22-2004, 08:13 PM
|
#5 (permalink)
|
|
Moderator
Join Date: 10-13-03
Location: UK
Posts: 2,819
Latest Blog: None
|
And this way it needs a <base href=""> elemtent before any external files are linked in the HTML (images, javascripts, css files, movies etc).
well thanks for ya help LJ! 
|
|
|
03-23-2004, 05:41 AM
|
#6 (permalink)
|
|
No Longer Here
Join Date: 09-27-03
Location: State College, PA
Posts: 9,354
Latest Blog: None
|
No problem 
|
|
|
03-23-2004, 09:21 AM
|
#7 (permalink)
|
|
Moderator
Join Date: 10-13-03
Location: UK
Posts: 2,819
Latest Blog: None
|
|
|
|
04-01-2004, 12:21 AM
|
#8 (permalink)
|
|
Inactive
Join Date: 10-22-03
Location: Bali Island
Posts: 27
Latest Blog: None
|
use .htaccess mod_rawrite ?
|
|
|
04-01-2004, 03:37 AM
|
#9 (permalink)
|
|
Moderator
Join Date: 10-13-03
Location: UK
Posts: 2,819
Latest Blog: None
|
Using PHP I can do searches on my site too, rather than just fling them at a page.
Plus I don't have to play with funny reg-ex patterns that not many ppl understand very well.
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 02:14 PM.
© Copyright 2008 V7 Inc
|