Posted May 31, 2004 in si-blog.

Thanks to some great help from Basil Crow, I now have enough knowledge of Apache's mod_rewrite to achieve the URL rewriting I've been hoping for. In the next iteration of this blog, I expect the following:

Preferred URL
Actual URL
mod_rewrite rule
RewriteRule ^archive/([0-9]{4})?/?([0-9]{1,2})?/?([0-9]{1,2})?/?([_0-9a-z-]+)?/?$ (break)
/archive/index.php?y=$1&m=$2&d=$3&slug=$4 [QSA]

I should also thank Anne, Mike, and Simon for pushing me in the right direction.

Here's a question: Should there be a trailing slash after the "slug", like, or is that wrong?


  1. Gravatar

    The trailing slash issue is difficult. On my own blog I opted to go without, but later realised that it was very difficult to decide on edge cases - for example. On a recent work project we made the decision to ALWAYS include a trailing slash (and add one via redirect if it wasn't there in the first place) and this has lead to far less ambiguity - for an example. On balance, I'd say always stick a trailing slash on as it ends up being less confusing.

    Posted by Simon Willison on May 31, 2004.

  2. Gravatar

    Nice to hear something from an 'official voice' like Simon on this.

    I've always used the trailing slash, but have noticed that sometimes explorer saves the url without the last slash (when you're typing it in and it pops up in the dropdown).

    Posted by Mike P. on May 31, 2004.

  3. Gravatar

    I never use the trailing slash (using a 301 to the none slash version) and I'm probably wrong doing so, since I want 'bar' and 'bar/' to be different, which is not the case.

    I won't change it however since it works perfectly, perhaps they will change the specification once...

    Posted by Anne on May 31, 2004.

  4. Gravatar

    Simon, those rewrites look like the WP one's. Actually, the prefered URL is exactly the one I am using right now! Very nice!

    Hey, OT, what does the :) on the side of the link means? Updated? Curious... :-)

    Posted by David Collantes on Jun 01, 2004.

  5. Gravatar

    I think I will use the trailing slash.

    David, the smileys in my "out there" list are put there using generated content. They depend on the value of the REL attribute (XFN relationship). The :) next to your name means "friend". You can see the relationships by right-clicking on the link in Firefox and selecting Properties. Incidentally, the pushpin before "vtrdesigns" means "met".

    Posted by Simon Jessey on Jun 01, 2004.