Patch from Eugene Crosser (@crosser) used to cope with permalinks