The first thing you need to do is dump your $_SERVER object and have a look to see what you can work with. Obviously we want to do as little work as possible. So, here is a list of all the objects in my $_SERVER object:
UNIQUE_ID tL@eRtBxlBIAAA6-fg4AAAAF SCRIPT_URL /corpus/PFHET/another/query/for/your/pleasure/ SCRIPT_URI http://www.hypergeneric.com/corpus/PFHET/another/query/for/your/pleasure/ HTTP_HOST www.hypergeneric.com HTTP_USER_AGENT CCBot/1.0 (+http://www.commoncrawl.org/bot.html) HTTP_ACCEPT Accept: application/xhtml+xml,text/html;q=0.9,text/plain; HTTP_ACCEPT_LANGUAGE en-us,en;q=0.5 HTTP_ACCEPT_ENCODING gzip HTTP_ACCEPT_CHARSET ISO-8859-1,utf-8;q=0.7,*;q=0.7 HTTP_CONNECTION close HTTP_CACHE_CONTROL no-cache HTTP_PRAGMA no-cache PATH /bin:/usr/bin:/sbin:/usr/sbin SERVER_SIGNATURE SERVER_SOFTWARE Apache/2.0.61 (Unix) PHP/4.4.7 mod_ssl/2.0.61 OpenSSL/0.9.7e mod_fastcgi/2.4.2 DAV/2 SERVER_NAME www.hypergeneric.com SERVER_ADDR 208.97.191.152 SERVER_PORT 80 REMOTE_ADDR 38.103.63.62 DOCUMENT_ROOT /home/reductio/hypergeneric.com SERVER_ADMIN webmaster@hypergeneric.com SCRIPT_FILENAME /home/reductio/hypergeneric.com/corpus/PFHET REMOTE_PORT 44693 GATEWAY_INTERFACE CGI/1.1 SERVER_PROTOCOL HTTP/1.1 REQUEST_METHOD GET QUERY_STRING REQUEST_URI /corpus/PFHET/another/query/for/your/pleasure/ SCRIPT_NAME /corpus/PFHET PATH_INFO /another/query/for/your/pleasure/ PATH_TRANSLATED /home/reductio/hypergeneric.com/another/query/for/your/pleasure/ PHP_SELF /corpus/PFHET/another/query/for/your/pleasure/ argv Array argc 0
So, looking at this, the server is doing all the work for me. Clearly, PATH_INFO is perfect as it has everything right after the "action" filename. Now, don't get your hopes up. It usually isnt quite this nice. You may find that you will need to do a little string magic with the REQUEST_URI and the PHP_SELF.
So, my "query" then is:
/another/query/for/your/pleasure/
The code looks like:
$query = $_SERVER["PATH_INFO"];
Another thing to consider, if you plan on using relative urls (like in the head), if you plan on using forward-slashes in the url, the html page that is rendered uses the path of the search bar to determine the relative paths. So, inherently, it won't work. You'll have to use a bit of php again to figure out how many directories the page will think it's ahead, and then create a variable you can echo. For example: for the query you've posted to this page i am prefixing all my relative urls with:
../../../../../
The code looks like:
$directories = count(explode("/", trim($query, "/")));
$fileroot = "";
for ($i=0; $i<$directories; $i++) $fileroot .= "../";
Then you just put this everywhere you have a url:
<? echo $fileroot ?>
Makes sense? I think it's actually pretty easy. The only other thing you have to do, of course, is create a .htaccess file. Oh, and prey that the installation of Apache you are running allows them. The .htacess file for getting this page to work is:
<Files PFHET> SetHandler application/x-httpd-php </Files>
Now get out there and start cleaning up those URL's! Hide that .php shit and the ?'s and whatnot. You haven't lived until you have parsed your own PFHET query!