[thelist] Re: PHP and / instead of ?
RUST Randal
RRust at COVANSYS.com
Fri Jan 17 06:41:00 CST 2003
Tim Luoma said:
> Instead of
>
> /path/to/this?20020704
>
> I'd like to be able to use
>
> /path/to/this/20020704
>
> I read the PHP entry for 'explode' but I think it's beyond me
> (my PHP is pretty rudimentary).
I went through this very exercise a few months back. In the parent directory
of my site, I added an .htaccess file that looks like this...
<FilesMatch "^index$">
ForceType application/x-httpd-php
</FilesMatch>
This forces any file called "index" to be executed as PHP. Since it's
called index, it's still what the server points to when it enters the
directory. Although I may be forgetting something here, I don't think that
I did anything with Apache to set this particular part up.
Then, in my index file, I have a PHP script that looks like this...
<?php
$path=$_SERVER['PATH_INFO'];
$content=explode("/", $path);
$content=array_reverse($content);
if($content[0]!=""){
$content=$content[0] . ".php";
include $content; }
else {
include 'home.php'; }
?>
It takes the requested path (http://www.server.com/home), turns it into an
array, reverses it, then adds the .php extension to 'home' and loads the
'home.php' file into the window. You can see it in action at
http://www.randalrust.com/r2/.
If you have any particular questions, let me know, I'd be more than willing
to give you a hand with this.
----------
Randal Rust
Covansys, Inc.
Columbus, OH
More information about the thelist
mailing list