Fixed incorrect edge case hostname parsing.

These two gists demonstrate what the PR fixes,

Before: https://gist.github.com/stdexcept/6449348
After: https://gist.github.com/stdexcept/6449363

Notice how using an alias screws up the url and port.