URI encode IDs before replacing them in URL.  Fixes #290
Fix variable name typo - fixes #767