This is less than ideal.  We are taking apart the URL above, and then very slowly and oddly reassembling it, creating a bunch of extra string objects along the way, and throwing in some magic numbers for good measure...  Is there not a URL parsing lib we could be using here?