Blog Archive - part two: a better URL

As mentioned in the last entry, I wanted to avoid using query strings in the blog archive page. Fortuntately, Apache and PHP let you do that quite easily; simply call the script with a trailing slash in the URL after the scriptname, and add the data to pass to the script after that:

For example, to pass the id "2327" to the script archive.php, call it as: . The value '/2327' will be passed to the script in the variable $_SERVER['PATH_INFO'], from which you can easily extract the numeric part.

Of course this url still contains the string ".php", and so isn't as elegant as we might like it to be. We want to have a script that has no extension, but still gets recognised and executed as PHP by Apache.

Fortunately Apache lets you do this quite easily with Apache's ForceType directive, which can be used either in the main Apache configuration file, or in a .htaccess file in the directory of the script. The format is as follows:

<Files filename>
ForceType application/x-httpd-php

substituting filename as appropriate.

This allows us to be a bit more flexible with filenames, so on this site I've used the name 'byjid' (by-journal-id) for the script, so that the URL for the first post on this site is:

Full details on the ForceType directive can be found at , and details on <Files> at .
Posted by parsingphase, 2004-04-09 19:24

Anonymous user



Contact Richard