Make link rewriting honor template/page restrictions