make permalinks work properly + fix cukes. manual cherry-pick of 466

I believe this fixes #479. Needs review before merge please