Change the way with detect base URL

This follow the spec more closely, even if we are not totally compliant.

Related to heroku/prmd#83.