NYCPHP Meetup

NYPHP.org

[nycphp-talk] Friendly URLS... The easy way!

Kenneth Downs ken at secdat.com
Tue Aug 7 07:07:17 EDT 2007


Elliotte Harold wrote:
> Paul Houle wrote:
>> There's an easy way to get 'friendly' URLs in PHP.  There are two 
>> tricks involved:
>>
>> (1) It seems to be a bit obscure that if you have a PHP script at
>>
>> http://somewhere.com/myscript.php
>>
>> the same script is called if you visit
>>
>> http://somewhere.com/myscript.php/some/subdirectories.gif
>> http://somewhere.com/myscript.php/article/2007/07/07/hello-world
>>
>> Try it!  
>
>
> Amazing! I did just try it and that actually works. You can use a PHP 
> script to replace a directory. I thought there had to be something 
> that easy, but I've never seen it done that way.
>
> I think what Ken last suggested amounts to the same thing, but I 
> couldn't quite see how his example actually worked.

Yes, they amount to the same thing, but one has the .php extension and 
one does not.

It was weird to me when pointed out at first.  What the .htaccess 
setting is doing is telling Apache to process an entry that looks like 
'news' as a php script.  Also, "entries" here means a file or a 
directory segment.  The key is knowing that apache parses from left to 
right, not the other way around.  So as soon as it finds 'news', it 
passes control to that file as a php script and apache itself is now 
finished.

>
> It is indeed pretty obscure. I wonder if this is documented anywhere?
>
>
Methinks its a basic apache thing.

-- 
Kenneth Downs
Secure Data Software, Inc.
www.secdat.com    www.andromeda-project.org
631-689-7200   Fax: 631-689-0527
cell: 631-379-0010




More information about the talk mailing list