Fix backlink problems on pages with slugs

I have tested this in various threads on multiple boards, and the issues should be fixed.

Fixes #1580 and #1589