Discourse rewriting url path behaviour failing due to subfolder

It works fine when you browse to such a topic, it only fails when you come from a direct URL.