Generate correct relative paths even for pages in the root

Previous code generated '/' for the path to the root, which is not
relative and causes problems when changing paths with http proxies.
Fixes #2544.