Fixed url encoding for slash switching emulation.

Fixes #8458
This will break if there's a question mark after the hash. We want the lesser of the two indices.