NYCPHP Meetup

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

Paul Houle paul at devonianfarm.com
Mon Aug 6 21:19:02 EDT 2007


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!  You can make your script display something different based on 
the path
you enter by checking the superglobal $_SERVER["PATH_INFO"].  From simple
if-then-else ladders to advanced frameworks,  you can take it from there 
as you wish.

(2) You can remove the ".php" from your scripts by putting the following 
in your
.htaccess or apache configuration:

DefaultType application/x-httpd-php

Now if you have a script without an extension (say,  "myscript") you can 
write

http://somewhere.com/myscript/some/subdirectories.gif
http://somewhere.com/myscript/article/2007/07/07/hello-world






More information about the talk mailing list