Feed Sign in with OpenID OpenID

Simon Willison’s Weblog

Sensible URLs with PHP

Brent Simmon’s Law of CMS URLs:

The more expensive the CMS, the crappier the URLs.

The article includes an interesting comments thread discussing human readable URLs and why so many high end content management systems just don’t bother with them. There are a couple of interesting links as well: User-Centered URL Design and a useful description of how Vignette StoryServer URLs are structured.

I am a big fan of logical URLs (as can be seen on this site)—the combination of PHP and Apache makes it easy to have all requests to a specific sub-directory of a site handled by a single script. Here’s the .htaccess file for the root directory of my blog:

<Files archive>
  ForceType application/x-httpd-php 
</Files>
<Files categories>
  ForceType application/x-httpd-php
</Files>
<Files contact>
  ForceType application/x-httpd-php
</Files>
<Files syndicate>
  ForceType application/x-httpd-php
</Files>

The following PHP code (or a variation of it) is then used to break the requested URL up in to an array which can then be processed to decide what content to serve the user:

$path = $_SERVER['REQUEST_URI'];
$bits = explode('/', $path);

This is Sensible URLs with PHP by Simon Willison, posted on 4th October 2002.

View blog reactions

Next: Eric has permalinks

Previous: .NET saves Boy!

3 comments

  1. You can make your .htaccess file smaller by using regular expressions like this:

    <Files ~ (archive|categories|contact|syndicate)>
      ForceType application/x-httpd-php
    </Files>
    

    ;-)

    MiMaS - 6th October 2002 08:35 - #

  2. Aha, always wondered how this was done. Many thanks. One thing though. Am I right in think that there is a file called archive.php in the root and one called contact etc etc?? If not, how so?

    Jake Howlett - 10th October 2002 10:30 - #

  3. I had this working on our site, but just moved to a new server and it broke. What would it be in the Apache build that would make this incompatible?

    Note: it will parse a file without a variable, but when you add /variable onto the url, it results in a page not found.

    Colin - 9th December 2005 18:49 - #

Comments are closed.

Previously hosted at http://simon.incutio.com/archive/2002/10/04/cmsUrls

A django site