Improve handling of URL identifiers and file extensions.

Instead of indiscriminately appending non-query identifiers to the URL, replace
the file extension if the identifier represents an alternate extension.  An
identifier is considered to represent an alternate extension if the strings
starts with a `.` character.  Also, prevent duplicate characters if both the
path ends with and the identifier starts with `/`.

Can you add a comment here or in the function comment about how this behavior works.