Cool URLs

  Jul 01, 2003

Hopefully nobody noticed, but I've changed the URL to every document on this website. The old URLs work too, but this site has officially moved from http://jogin.com/blog/ to http://jogin.com/weblog/.

Other than that, documents have moved around according to the following patterns:

  • Individual archives
    • Used to be at: /blog/archives/000319.php
    • Are now at: /weblog/archives/000319/
  • Monthly archives
    • Used to be at: /blog/archives/2003_07.php
    • Are now at: /weblog/archives/2003/07/
  • Master archive
    • Used to be at: /blog/archives.php
    • Is now at: /weblog/archives/
  • Author page
    • Used to be at: /blog/author.php
    • Is now at: /weblog/author/
  • Search page
    • Used to be at: /blog/search.php
    • Is now at: /weblog/search/
  • Links page
    • Used to be at: /blog/links.php
    • Is now at: /weblog/links/
  • RSS 2.0 Feed
    • Used to be at: /blog/jogin.com.blog.xml
    • Is now at: /weblog/feed.rss
  • RSS 1.0 Feed
    • Used to be at: /blog/jogin.com.blog.rdf
    • Is now at: /weblog/feed.rdf

The old /blog/ directory has really -- physically -- been moved to /weblog/, but the file structure beneath that level is physically unchanged. I've just used a little bit of mod_rewrite to serve requests of, for instance, /weblog/archives/000319/, the file located at /weblog/archives/000319.php. Why? Because it's more neat.

So, why not just change where MT stores the files? Because that would mean that, for instance, an individual archive would physically be stored at /weblog/archives/000319/index.php, which is un-neat. Shh, don't object. It is.

The mod_rewrite rules to redirect requests of individual and monthly archives looks like this:

RewriteRule ^(\d{6})/$ $1.php [L]
RewriteRule ^(\d{4})/(\d{2})/$ $1_$2.php [L]

So, from now on my individual archives are, ostensibly and virtually, located like so: /weblog/archives/000319/. But, requests adhering to the old file structure, for example those of /weblog/archives/000319.php will naturally work too, since that's where the file actually is. Here comes the tricky part: I'd like to tell requests of /weblog/archives/000319.php that the file has permanently moved to /weblog/archives/000319/, using the following mod_rewrite rule:

RewriteRule ^(\d{6}).php$ $1/ [R=301,L]

In effect, I'd like to redirect those who are requesting files from the old location to the new location, and serve the file located at the old (and current, remember?) place to those who request it from the new location.

Unfortunately, that would create an infinite loop since the two mod_rewrite rules would send the visitor back and forth between one another. I've tried to solve this predicament with different kinds of mod_rewrite flags, but to no avail. If there is a mod_rewrite wizard reading this, feel free to tell me how I could best solve this problem, using mod_rewrite.

I was originally going to point to a document at W3C, called "Cool URIs Don't Change" which explains why this kind of directory structure is to prefer over serving files revealing and using the file extension, unfortunately they changed the URL to it, or removed it completely, so I can't. Oh, the irony.

Update:

Solved the problem with the infinite loop; any requests for pages located in the "old" location will get a "301 Moved Permanently" answer and are redirected to the new location, which serves the file located in the "old" location.

Permanent link

Comments

The discussion has been closed on this entry. Thanks to everybody who participated.