RE: [PHP] Using $PATH_INFO as variables (inspired by www.DevShed.com)
| From: | Matt Williams | Date: | Wed, 30 Jan 2002 13:27:37 +0000 |
| Subject: | RE: [PHP] Using $PATH_INFO as variables (inspired by www.DevShed.com) | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-82731@lists.php.net to get a copy of this message | ||
m:
> my main URL (for example) is www.mycompany.com
> I want the central page about our projects to be found under
> www.mycompany.com/projects
> and project LovePeaceAndBananas under
> www.mycompany.com/projects/LovePeaceAndBananas
>
> I already know that this can be achieved by using the $PATH_INFO as
> variables, to be used in de main file in the root of the site.
> So far I have my Apache webserver accept files with no extention
> (index, in
> stead of index.php) to be parsed as PHP. But if I look at the site of
> DevShed, I don't see them using a file at all! I can't get it to
> work on my
> local test system to make an URL like
> www.mycompany.com/projects/LovePeaceAndBananas without the existens of a
> file called 'projects'.
> Can anyone tell me their 'trick'? (unfortunately, they don't show
> their page
> source anymore like they used to do ...)
>
Hi
see this page for more details
http://www.phpbuilder.com/columns/tim19990117.php3
You do actually need the file called projects. This is the file that does
all the work.
It didn't quite work exactly as that for me, so here's what I did just in
case you need it.
add the follwoing into .htaccess under you site root
## set rewrite rule for author
RewriteRule ^/projects/(.*) /projects?rest_of_url=/$1
Then add this to your projects file
$_MY_PATH = explode("/",$PATH_INFO);
array_shift($_MY_PATH);
This will give you the array of elements that come after projects.
i.e /projects/LovePeaceAndBananas/one
$_MY_PATH[0] // this will be LovePeaceAndBananas
$_MY_PATH[1] // this is one
etc....
HTH
m: