Make sure history.jsp doesn't strip off too much when creating a relative path name.

Fixes #649.

Moved the logic from history.jsp to a helper method in Util so that it can be tested by a unit test.