Added permalink rewrite code from 6.1