Minor fix for permalinks rewriting

Fixed a problem where at given circumstances, the wrong part of a URL
would be replaced, thus ending up with incorrect permalinks.