I'm trying to build dynamic pages in PHP with pretty URLs. I've decided that
this pretty much means encoding URL arguments you'd typically place in a GET
query (ie, ../user.php?username=jeff) into something that can be read
through $PATH_INFO (ie, ../user.php/jeff). This is not just a matter of
making things friendly to search engines...it's also a matter of usability
and of neurotic aesthetics.
As far as I can tell, this is easily done when the script is clearly
identifiable in the URL...Apache knows immediately that something like
"*.php" is a script and will simply ignore the trailing URL bits when
serving up the script. What I'd like to do is to somehow entirely circumvent
having to place filename extensions on scripts (ie, having "../user" instead
of "../user.php"). For example, http://www.freshmeat.net has a very, very
pretty way of handling dyanmic pages with very intuitive URLs, and they
indicate nothing about the scriptness of the underlying documents.
Getting Apache to parse every file without an extension as a PHP script
turns out to be pretty hard, and that's where I need help.
Using the "AddType" directive under mod_mime doesn't work--by its very
nature you have to have a file extension to be able to determine its MIME
type, and thus a script called "user.php" and an identical script called
"user" are two very different things.
I tried using mod_mime_magic to look for something obvious in the beginning
of an extension-less file...something like "<?php" or whatever...but I
either did not configure it properly or this will not work. Also, this is of
no help if I don't have direct access to the magic file, or if mime_magic
isn't loaded on my web host (in other words, when I don't have my own
server).
One way to move around this would be using .htaccess and mod_rewrite,
provided it was loaded on the server. Basically, I would try to craft some
kind of program logic that would examine each component of the URL (ie,
.../user/...) and check to see if a corresponding *.php file existed (ie,
../user.php), and then internally redirecting the request that way. But
somehow this seemed to me to be horribly convoluted and would probably
require plugging an external rewrite map into mod_rewrite.
So...what's the best way to do this? Am I horribly complicating a simple
affair, or horribly oversimplifying a complicated affair? A thousand tips of
the hat those bold souls who can help out.