Pretty URLs

LnBlog grew a new feature this week: pretty URLs. And it's about time, too. I never really worried too much about the URLs being largely numeric, but after a year of looking at my logs and my own links, trying to figure out what an entry was about, I've now changed my tune.

I think the solution I came up with is fairly simple. When an entry is created or edited, a PHP wrapper script will be created in the same directory as the entry. All the script will do is change to the entry directory and call the index.php file there. It will be named using the entry subject with all non-word characters (everything but numbers and letters) converted into underscores and a PHP suffix tacked onto the end. If this file exists, it will be used as the permalink for the entry. So, for example, the permalink for this entry will be http://www.skepticats.com/lnblog/entries/2006/01/Pretty_URLs.php. I'll probably make this configurable so that people can still use the old-style URLs (in part because I'm not sure how I should handle non-Latin subject text), but the new ones will be the default.

There are a two main benefits to doing it this way:

  1. There is no need for conversion. All the old URLs will continue to work.
  2. Permalinks will not break if you edit an entry's subject. A new script will be created using the correct subject text, and will be used as the permalink in the future, but the old one will continue to point to the same location.

I suppose I'll probably release the next version soon. I want to add a few other changes, including some more hooks into the way entries are displayed to make plugins easier to write. One thing I'd like to include in the next few releases is a comment spam plugin, although I haven't really needed one so far. I just need to lay the groundwork first.

You can reply to this entry by leaving a comment below. This entry accepts Pingbacks from other blogs.

Add your comments #

A comment body is required. No HTML code allowed. URLs starting with http:// or ftp:// will be automatically converted to hyperlinks.