Detect and remove prefix being added twice when going to pages already in history

This resolves the issue that discourse run with prefix sometimes generates URLs like /discourse/discourse/t/...

This can be reproduced by running discourse with a prefix, going to http://127.1/discourse/, then clicking on any topic, going back (using back button) and then clicking on same topic again.