Viewing Entries For
September
2011
[clear date selection]
A few days ago, David Flinner posted a comment via Google+ about a blog post I made recently. I saw the ugly URL back to my blog and clicked on it for no particular reason. My instance of MachBlog threw an exception because the URL contained a UUID with a trailing dot. When MachBlog searched for the post matching that primary key, it came up empty. This sort of problem happens all the time, and I don't know what is so difficult for spiders to pick up the proper URL. I know I should migrate someday — especially to something that could deal with human comments — but there are other things higher up on the todo list.
At any rate, I decided to take another look at my Apache URL rewriting rules and fix the issue. Previously, I was supporting a shortcut URL like /blog/UUID, which redirects to /machblog/index.cfm?event=showEntry&entryId=UUID. I was also checking to see that incoming URLs had a proper UUID (the right number of hex values separated in the correct positions by dashes). I made a change to the rules so that trailing characters would be hacked off. Here are the new rules:
# MachBlog shortcut
RewriteRule ^/blog/([-a-f0-9]{35}) /machblog/index.cfm?event=showEntry&entryId=$1 [NC,R,L]
# URL decode a doubly-encoded UUID
RewriteCond %{QUERY_STRING} entryId=([.]{8})%2D([.]{4})%2D([.]{4})%2D([.]{16}) [NC]
RewriteRule .* /machblog/index.cfm?event=showEntry&entryId=%1-%2-%3-%4 [NE,R,L]
# Truncate extra characters
RewriteCond %{QUERY_STRING} entryId=([-a-f0-9]{35})[^&] [NC]
RewriteRule .* /machblog/index.cfm?event=showEntry&entryId=%1 [NE,R,L]
Note that it's important to use the no-escape (NE) flag on the rewrite so that extra URL encoding isn't introduced.
Here's a mini, nay micro, tip on Java regex goodness. I often build up URLs from bits and pieces of strings where there is not a strict convention for whether a leading/trailing slash should exist before/after a directory. The easiest way to deal with this situation is to use the directory separator character gratuitously, and strip out doubles afterwards. Consider the following:
<cfset host = "localhost"/>
<cfset filepath = "/downloads/file.txt">
<cfset earl = "http://" & host & "/context/" & filepath/>
Most web servers don't actually care if there's an extra double-slash where there should be just one, as in http://localhost/context//downloads/file.txt. However, there's a simple way to fix up the URL using the String.replaceAll() method. It takes a regular expression that supports negative lookbehind, which prevents the double-slash following the colon from being molested:
<cfset earl = earl.replaceAll("(?<!:)//", "/")/>
Boom! Done.
CFML,
Java
|
Posted
9/13/11
@ 4:57 PM
by Joseph Lamoree
This post will probably be useful to about four people in the world. But I'll throw it up here for their benefit.
I installed a copy of Firefox 6.0.1 to do some work on HTML5 forms. So that it wouldn't discombobulate my existing Firefox 3.6.21 installation with all my development gadgetry, I created a secondary Mozilla profile path. While loading pages with the latest Firefox, I saw that proxied requests were not appearing in the Charles window. Normally the extension that Charles provides to turn on/off HTTP proxying is installed automatically. I believe that because I was using a copy of Firefox in a weird location with a foreign profile, it didn't do its magic.
So, here's how to install the extension manually. Extract the XPI from the main Java Archive:
unzip -j -d ~/Downloads /Applications/Charles.app/Contents/Resources/Java/charles.jar charles.xpi
Then open the Add-ons Manager and choose Install Add-on From File... from the actions menu. Browse to the file from the Downloads directory. Et voilá!
Firefox
|
Posted
9/1/11
@ 6:17 AM
by Joseph Lamoree