Note: I was having issues using realpath() -- something to do with realpath() on shared Windows servers. It did work with this realpath alternative in its place, however.

Credit goes out to the open scripts out there I consulted in creating this one. Curiously, the PEAR HTTP:absoluteURI() did not successfully do this for me. Perhaps I wasn't using it as intended. But it did help me figure out how to build the url head.