Normalize URI handling with trailing slashes

Implementation is consistent with the one proposed in #532