I'm hacking around on the email-to-twitter thing a bit tonight (almost done with version one so watch for that announcement probably tomorrow)...anyway as part of it, I needed to do some Apache rewrite stuff...and I thought it was cool enough that I would just share it up here as tonight's post.
Basically what I wanted to do was execute the code if the script exists...otherwise, I want to assume the user is attempting to access a message and is passing in a message key.
To accomplish this, I basically have to check if a file exists...if it does, just go to it, but if it doesn't take whatever was passed and use it as the key for the viewmessage.php script.
Of course I had to have mod_rewrite installed and enabled for apache2 ... but I'm not going to go into those details right now (do a google search for 'mod_rewrite apache' if you need help, the first few results will have all the gory details).
Anyway, here's the rules I put in place (that seem to be working pretty good so far):
RewriteEngine On
# Is the request for a non-existent file?
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ([a-zA-Z0-9]+) viewmessage.php?id=$1 [NC]



