Cools URI doesn’t change:- What makes a cool URI? A cool URI is one which does not change. What sorts of URI change? URIs don’t change: people change them - Tim Berners Lee
I can’t believe that the article was written in 1998 and only now I can value how much it worth, at least for me. In php, there’s some way we could hide php so people won’t know that you are using php to generate the page. Somehow, this is considered as silly approach by certain people who argue that it is ‘security through obscurity’. To me , this is not a matter of security but more to how to present your application. Your user should not be burdened out to think how did you implemented the application. Their concern only lies in how to access it and use it. We could see everywhere from the typical forum board to e-commerce and government websites something like:-
http://forums.com/index.php?showtopic=17744&view=getnewpost
https://bank.com/mbb/scripts/mbb_login.jsp?do=Login
http://shop.com/customer.php?id=123&orderid=56
URIs that doesn’t really make sense to the user and sometimes even hard to explain. It totally against the ‘don’t make me think’ principle. Try to compare the above URI with these:-
http://forums.com/topic/17744/newpost
https://bank.com/login
http://shop.com/customer/123/order/56
With such URIs, you can even use it as an interface to the application. I want a details of customer with id 123, just go to http://site.com/customer/123. I want to see all the orders that customer 123 has made, just go to http://site.com/customer/123/orders. Using a a clean and consistent URI would uniformly structured your site. The second benefit to clean and uniform URI is it would abstract out your application. User don’t need to know how you implement your application. They doesn’t care whether you use HTML, PHP, ASP, JSP, Python etc to generate the page. They just want to access the page and get the information so why bother putting something like .html, .php in your URI ? By abstracting, it would also ease you in the process of migration. Let say you feel that php is sucks and want to implement your cool web 2.0 application in Python. Since your application were accessed by user uniformly through URI such as http://site.com/node/123, the migration could be done seamlessly without affecting how they will access your next cool application.
There’s few approach you could take if you want to implement a clean URL in your application. Framework such as Rails, Django or web.py support it natively and if you are using php, you can leverage the powerful apache mod_rewrite. Yeah, I mentioned somewhere in my blog that I hate mod_rewrite, now I have to take back that word. Drupal for example, use a simple mod_rewrite rule and a short function to parse the url and dispatch it to php callback. Simply put, it’s not hard to implement and it’s worth the effort. Tim Berners Lee was talking about it since 1998, at least we pay him some respects :)

Comments
I've been doing this for
I've been doing this for some time in PHP and without the need for mod_rewrite in many cases. Many php frameworks already support this natively.
Ditesh
I wonder how’d you achieve
I wonder how’d you achieve that without
mod_rewrite. Even Zend Framework depends onmod_rewritebased on their documentation. If you mentioned about usingPATH_INFO, I found it to be inconsistent in different PHP versions. I’ve try experimenting with clean url without mod_rewrite but it use lighttpd error handler to redirect the request to index.php (or any controller you wish) but does not work with apache which lost the POST data after redirect.-kamal-
Yes, you would use PATH_INFO
Yes, you would use PATH_INFO and it's fairly trivial to implement - you do not need mod_rewrite. WACT uses it. The problem with mod_rewrite is the complexity of that module.
What are the versions you have had problems with? I have not had problems with php 4.x and 5.x versions that I have used with apache httpd.
Ditesh
can’t really remember, the
can’t really remember, the last time it broke all my code which used
PATH_INFOand a check with phpinfo() show’s that PATH_INFO is not present, thus giving me a feeling thatPATH_INFOis not reliable to be used for url traversal. I think it wasmod_phpthat comes with Opensuse 10.0. The cgi version doesn’t have the problem.but with
PATH_INFO, your php was still exposed if not without the help from web server or does php.ini setting can help here ?I want the latter. maybe you have some nice trick here.
-kamal-
My development platforms
My development platforms tend to be FreeBSD and Fedora, the packaging of PHP is fine there. I deployed a fairly large and non-trivial PHP app on Suse (not OpenSuse) last year and that seems to be running fine too :-) However, I have seen people reporting problems on the -internals list wrt OpenSuse's packaging mechanism.
I didn't understand your second question/note.
Regards,
Ditesh
to my understanding, we
to my understanding, we still need to specify the full path to the script, then we add the
PATH_INFO. For example,[
SCRIPT_FILENAME] - how we get here ? - http://site.com/index.php[
PATH_INFO] - what’s still left ? /customer/1/order/2so without help from
mod_rewritewe can’t have a clean url such as:-http://site.com/customer/1/order/2
the point is not to expose index.php (as it would exposed the implementation detail) or any
SCRIPT_FILENAME.thanks anyway for your comments.
-kamal-